From b1c63cddb988b6086486cfb739c07d33d872cafe Mon Sep 17 00:00:00 2001 From: John Naylor Date: Sat, 9 Dec 2023 17:58:59 +0700 Subject: [PATCH v7 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 a798c42ba7..6157124cb4 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