From f8200a0c75abc946eba85f55fa6d111d3d632b88 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Sat, 9 Dec 2023 17:58:59 +0700
Subject: [PATCH v6 11/13] Add abiliy to case-fold with chunk (8-byte)
 interface

---
 src/include/common/hashfn_unstable.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/include/common/hashfn_unstable.h b/src/include/common/hashfn_unstable.h
index 3c3690d063..6a1f40e70b 100644
--- a/src/include/common/hashfn_unstable.h
+++ b/src/include/common/hashfn_unstable.h
@@ -49,6 +49,7 @@ typedef struct fasthash_state
 {
 	uint64 accum;
 #define FH_SIZEOF_ACCUM sizeof(uint64)
+	uint64 overlay; /* used for case-folding */
 	int8	accum_len;
 	uint64 hash;
 } fasthash_state;
@@ -74,7 +75,7 @@ fasthash_combine(fasthash_state* hs)
 }
 
 static inline void
-fasthash_init(fasthash_state *hs, int len, uint64 seed)
+fasthash_init(fasthash_state *hs, int len, uint64 seed, bool case_fold)
 {
 	memset(hs, 0, sizeof(fasthash_state));
 
@@ -82,6 +83,9 @@ fasthash_init(fasthash_state *hs, int len, uint64 seed)
 	// handle some other way -- maybe we can accum the length in
 	// the state and fold it in during the finalizer (cf. xxHash3)
 	hs->hash = seed ^ (len * UINT64CONST(0x880355f21e6d1965));
+
+	if (case_fold)
+		hs->overlay = UINT64CONST(0x2020202020202020);
 }
 
 static inline void
@@ -123,6 +127,8 @@ fasthash_accum(fasthash_state *hs, const unsigned char *k, int len)
 		case 0:
 			return;
 	}
+		/* case-fold, if set */
+		hs->accum |= hs->overlay;
 
 	fasthash_combine(hs);
 }
@@ -154,7 +160,7 @@ fasthash64(const unsigned char * k, int len, uint64 seed)
 {
 	fasthash_state hs;
 
-	fasthash_init(&hs, len, seed);
+	fasthash_init(&hs, len, seed, false);
 
 	while (len >= FH_SIZEOF_ACCUM)
 	{
-- 
2.43.0

