* Returns 64-bit value by hashing a value to a 64-bit value, with a seed. * Otherwise, similar to hash_array. */
| 4178 | * Otherwise, similar to hash_array. |
| 4179 | */ |
| 4180 | Datum |
| 4181 | hash_array_extended(PG_FUNCTION_ARGS) |
| 4182 | { |
| 4183 | LOCAL_FCINFO(locfcinfo, 2); |
| 4184 | AnyArrayType *array = PG_GETARG_ANY_ARRAY_P(0); |
| 4185 | uint64 seed = PG_GETARG_INT64(1); |
| 4186 | int ndims = AARR_NDIM(array); |
| 4187 | int *dims = AARR_DIMS(array); |
| 4188 | Oid element_type = AARR_ELEMTYPE(array); |
| 4189 | uint64 result = 1; |
| 4190 | int nitems; |
| 4191 | TypeCacheEntry *typentry; |
| 4192 | int typlen; |
| 4193 | bool typbyval; |
| 4194 | char typalign; |
| 4195 | int i; |
| 4196 | array_iter iter; |
| 4197 | |
| 4198 | typentry = (TypeCacheEntry *) fcinfo->flinfo->fn_extra; |
| 4199 | if (typentry == NULL || |
| 4200 | typentry->type_id != element_type) |
| 4201 | { |
| 4202 | typentry = lookup_type_cache(element_type, |
| 4203 | TYPECACHE_HASH_EXTENDED_PROC_FINFO); |
| 4204 | if (!OidIsValid(typentry->hash_extended_proc_finfo.fn_oid)) |
| 4205 | ereport(ERROR, |
| 4206 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 4207 | errmsg("could not identify an extended hash function for type %s", |
| 4208 | format_type_be(element_type)))); |
| 4209 | fcinfo->flinfo->fn_extra = (void *) typentry; |
| 4210 | } |
| 4211 | typlen = typentry->typlen; |
| 4212 | typbyval = typentry->typbyval; |
| 4213 | typalign = typentry->typalign; |
| 4214 | |
| 4215 | InitFunctionCallInfoData(*locfcinfo, &typentry->hash_extended_proc_finfo, 2, |
| 4216 | PG_GET_COLLATION(), NULL, NULL); |
| 4217 | |
| 4218 | /* Loop over source data */ |
| 4219 | nitems = ArrayGetNItems(ndims, dims); |
| 4220 | array_iter_setup(&iter, array); |
| 4221 | |
| 4222 | for (i = 0; i < nitems; i++) |
| 4223 | { |
| 4224 | Datum elt; |
| 4225 | bool isnull; |
| 4226 | uint64 elthash; |
| 4227 | |
| 4228 | /* Get element, checking for NULL */ |
| 4229 | elt = array_iter_next(&iter, &isnull, i, typlen, typbyval, typalign); |
| 4230 | |
| 4231 | if (isnull) |
| 4232 | { |
| 4233 | elthash = 0; |
| 4234 | } |
| 4235 | else |
| 4236 | { |
| 4237 | /* Apply the hash function */ |
nothing calls this directly
no test coverage detected