Replace Scope.elements to use a custom hash map ScopeMap

This hash map is robin hood based with a inline slot amount for small scopes
This commit is contained in:
gingerBill
2026-03-16 17:41:58 +00:00
parent 1744f57d01
commit 36d5a19115
10 changed files with 374 additions and 81 deletions

View File

@@ -123,10 +123,11 @@ gb_internal bool ptr_set_update(PtrSet<T> *s, T ptr) { // returns true if it pre
usize hash_index = (cast(usize)hash) & mask;
GB_ASSERT(hash_index < s->capacity);
for (usize i = 0; i < s->capacity; i++) {
T *key = &s->keys[hash_index];
GB_ASSERT(*key != ptr);
if (*key == (T)PtrSet<T>::TOMBSTONE || *key == 0) {
*key = ptr;
T *key_ptr = &s->keys[hash_index];
T key = *key_ptr;
GB_ASSERT(key != ptr);
if (key == (T)PtrSet<T>::TOMBSTONE || key == 0) {
*key_ptr = ptr;
s->count++;
return false;
}
@@ -161,10 +162,11 @@ gb_internal bool ptr_set_update_with_mutex(PtrSet<T> *s, T ptr, RWSpinLock *m) {
usize hash_index = (cast(usize)hash) & mask;
GB_ASSERT(hash_index < s->capacity);
for (usize i = 0; i < s->capacity; i++) {
T *key = &s->keys[hash_index];
GB_ASSERT(*key != ptr);
if (*key == (T)PtrSet<T>::TOMBSTONE || *key == 0) {
*key = ptr;
T *key_ptr = &s->keys[hash_index];
T key = *key_ptr;
GB_ASSERT(key != ptr);
if (key == (T)PtrSet<T>::TOMBSTONE || key == 0) {
*key_ptr = ptr;
s->count++;
return false;
}