From eb0faf9602224eb1ab381e28ac7b41b71ada3fbc Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 5 Nov 2021 17:58:11 +0000 Subject: [PATCH] Unify hash logic for `PtrSet` --- src/ptr_set.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp index 37815c057..8dd3cb4dc 100644 --- a/src/ptr_set.cpp +++ b/src/ptr_set.cpp @@ -53,9 +53,8 @@ template gb_internal MapFindResult ptr_set__find(PtrSet *s, T ptr) { MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}; if (s->hashes.count != 0) { - u64 hash = 0xcbf29ce484222325ull ^ cast(u64)cast(uintptr)ptr; - u64 n = cast(u64)s->hashes.count; - fr.hash_index = cast(MapIndex)(hash & (n-1)); + u32 hash = ptr_map_hash_key(ptr); + fr.hash_index = cast(MapIndex)(hash & (s->hashes.count-1)); fr.entry_index = s->hashes.data[fr.hash_index]; while (fr.entry_index != MAP_SENTINEL) { if (s->entries.data[fr.entry_index].ptr == ptr) { @@ -72,9 +71,8 @@ template gb_internal MapFindResult ptr_set__find_from_entry(PtrSet *s, PtrSetEntry *e) { MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}; if (s->hashes.count != 0) { - u64 hash = 0xcbf29ce484222325ull ^ cast(u64)cast(uintptr)e->ptr; - u64 n = cast(u64)s->hashes.count; - fr.hash_index = cast(MapIndex)(hash & (n-1)); + u32 hash = ptr_map_hash_key(e->ptr); + fr.hash_index = cast(MapIndex)(hash & (s->hashes.count-1)); fr.entry_index = s->hashes.data[fr.hash_index]; while (fr.entry_index != MAP_SENTINEL) { if (&s->entries.data[fr.entry_index] == e) {