summaryrefslogtreecommitdiffstats
path: root/Hashtable.h
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-22 15:43:26 +0200
committerBenBE <BenBE@geshi.org>2020-11-17 02:01:02 +0100
commit307c34b028d353154aa268eceb38e0331c8275cf (patch)
tree25ef4307e553d0bfcda195e66f1171646641a738 /Hashtable.h
parent7914ec201ef19fa0c0caed99dc150a953eb9bc19 (diff)
Hashtable: use dynamic growth and use primes as size
Dynamically increase the hashmap size to not exceed the load factor and avoid too long chains. Switch from Separate Chaining to Robin Hood linear probing to improve cache locality. Use primes as size to further avoid collisions. E.g. on a standard kde system the number of entries in the ProcessTable might be around 650.
Diffstat (limited to 'Hashtable.h')
-rw-r--r--Hashtable.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/Hashtable.h b/Hashtable.h
index 15af9e0d..f7d1aae2 100644
--- a/Hashtable.h
+++ b/Hashtable.h
@@ -16,13 +16,13 @@ typedef void(*Hashtable_PairFunction)(hkey_t key, void* value, void* userdata);
typedef struct HashtableItem_ {
hkey_t key;
+ unsigned int probe;
void* value;
- struct HashtableItem_* next;
} HashtableItem;
typedef struct Hashtable_ {
unsigned int size;
- HashtableItem** buckets;
+ HashtableItem* buckets;
unsigned int items;
bool owner;
} Hashtable;
@@ -37,6 +37,8 @@ Hashtable* Hashtable_new(unsigned int size, bool owner);
void Hashtable_delete(Hashtable* this);
+void Hashtable_setSize(Hashtable* this, unsigned int size);
+
void Hashtable_put(Hashtable* this, hkey_t key, void* value);
void* Hashtable_remove(Hashtable* this, hkey_t key);

© 2014-2024 Faster IT GmbH | imprint | privacy policy