From 7135e1ce59239a88bcf664170ed63a617292a799 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 28 Aug 2025 16:47:53 +0800 Subject: [PATCH] Update namedict.c --- src/objects/namedict.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/objects/namedict.c b/src/objects/namedict.c index 7e89c6df..ea37932d 100644 --- a/src/objects/namedict.c +++ b/src/objects/namedict.c @@ -5,7 +5,20 @@ #include #include -#define HASH_KEY(__k) ((uintptr_t)(__k) >> 3U) +// https://jfdube.wordpress.com/2011/10/12/hashing-strings-and-pointers-avoiding-common-pitfalls/ +uintptr_t ThomasWangInt32Hash(void* Ptr) { + // Here we think only the lower 32 bits are useful + uint32_t Value = (uint32_t)(uintptr_t)Ptr; + Value = ~Value + (Value << 15); + Value = Value ^ (Value >> 12); + Value = Value + (Value << 2); + Value = Value ^ (Value >> 4); + Value = Value * 2057; + Value = Value ^ (Value >> 16); + return Value; +} + +#define HASH_KEY(__k) ThomasWangInt32Hash(__k) #define HASH_PROBE_0(__k, ok, i) \ ok = false; \