diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-10-21 21:25:59 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2020-11-17 02:01:02 +0100 |
commit | 7914ec201ef19fa0c0caed99dc150a953eb9bc19 (patch) | |
tree | 80849aa9cf7f0779c8a5816af0132533816bec74 /Hashtable.h | |
parent | 15eab2012d2100e1ddd20c186db23a8172b5858d (diff) |
Hashtable update
- use consistent type for key by introducing a new typedef
- use unsigned types for sizes
- name parameters in foreach function typedef
Diffstat (limited to 'Hashtable.h')
-rw-r--r-- | Hashtable.h | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Hashtable.h b/Hashtable.h index dcdc89fe..15af9e0d 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -10,36 +10,38 @@ in the source distribution for its full text. #include <stdbool.h> -typedef void(*Hashtable_PairFunction)(int, void*, void*); +typedef unsigned int hkey_t; -typedef struct HashtableItem { - unsigned int key; +typedef void(*Hashtable_PairFunction)(hkey_t key, void* value, void* userdata); + +typedef struct HashtableItem_ { + hkey_t key; void* value; - struct HashtableItem* next; + struct HashtableItem_* next; } HashtableItem; typedef struct Hashtable_ { - int size; + unsigned int size; HashtableItem** buckets; - int items; + unsigned int items; bool owner; } Hashtable; #ifndef NDEBUG -int Hashtable_count(Hashtable* this); +unsigned int Hashtable_count(const Hashtable* this); #endif /* NDEBUG */ -Hashtable* Hashtable_new(int size, bool owner); +Hashtable* Hashtable_new(unsigned int size, bool owner); void Hashtable_delete(Hashtable* this); -void Hashtable_put(Hashtable* this, unsigned int key, void* value); +void Hashtable_put(Hashtable* this, hkey_t key, void* value); -void* Hashtable_remove(Hashtable* this, unsigned int key); +void* Hashtable_remove(Hashtable* this, hkey_t key); -void* Hashtable_get(Hashtable* this, unsigned int key); +void* Hashtable_get(Hashtable* this, hkey_t key); void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); |