aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-11-05 17:58:11 +0000
committergingerBill <bill@gingerbill.org>2021-11-05 17:58:11 +0000
commiteb0faf9602224eb1ab381e28ac7b41b71ada3fbc (patch)
treeea13d207d4b3350ec7a0212cabaf6b4b1f22ea20
parent899cc719905b1b2f261c74867a322e8db9c1ac44 (diff)
Unify hash logic for `PtrSet`
-rw-r--r--src/ptr_set.cpp10
1 files 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 <typename T>
gb_internal MapFindResult ptr_set__find(PtrSet<T> *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 <typename T>
gb_internal MapFindResult ptr_set__find_from_entry(PtrSet<T> *s, PtrSetEntry<T> *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) {