array-hashing.patch

application/octet-stream

Filename: array-hashing.patch
Type: application/octet-stream
Part: 0
Message: 9.1 support for hashing arrays

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/utils/adt/arrayfuncs.c 0 0
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
new file mode 100644
index f521811..f1ecf4d
*** a/src/backend/utils/adt/arrayfuncs.c
--- b/src/backend/utils/adt/arrayfuncs.c
*************** hash_array(PG_FUNCTION_ARGS)
*** 3617,3627 ****
  		}
  
  		/*
! 		 * Combine hash values of successive elements by rotating the previous
! 		 * value left 1 bit, then XOR'ing in the new element's hash value.
  		 */
! 		result = (result << 1) | (result >> 31);
! 		result ^= elthash;
  	}
  
  	/* Avoid leaking memory when handed toasted input. */
--- 3617,3633 ----
  		}
  
  		/*
! 		 * Combine hash values of successive elements by multiplying the
! 		 * current value by 31 and adding on the new element's hash value.
! 		 *
! 		 * The result is a sum in which each element's hash value is
! 		 * multiplied by a different power of 31. This is modulo 2^32
! 		 * arithmetic, and the powers of 31 modulo 2^32 form a cyclic group of
! 		 * order 2^27. So for arrays of up to 2^27 elements, each element's
! 		 * hash value is multiplied by a different (odd) number, resulting in
! 		 * a good mixing of all the elements' hash values.
  		 */
! 		result = (result << 5) - result + elthash;
  	}
  
  	/* Avoid leaking memory when handed toasted input. */