27#define DEFAULT_HASHMAP_BUCKETS (4091)
96 for (bucket = 0; bucket < hashmap->
bucket_count; bucket++) {
97 for (entry = hashmap->
buckets[bucket];
118 for(;entry != NULL; entry = entry->
next) {
136 void *new_key, *new_value;
138 for(;entry != NULL; entry = entry->
next) {
143 if (new_key == NULL) {
148 if (new_value == NULL) {
155 entry->
value = new_value;
156 entry->
key = new_key;
163 entry = malloc(
sizeof(*entry));
169 memset(entry, 0,
sizeof(*entry));
172 if (entry->
key == NULL) {
178 if (entry->
value == NULL) {
184 if (entry->
next != NULL) {
188 hashmap->
buckets[bucket] = entry;
195 if (entry->
value != NULL)
197 if (entry->
key != NULL)
212 for(;entry != NULL; entry = entry->
next) {
217 if (entry->
next != NULL) {
235 for (uint32_t bucket = 0;
240 entry = entry->
next) {
242 if (cb(entry->key, entry->value, ctx))
struct hashmap_entry_s hashmap_entry_t
Hashmaps have chains of entries in buckets.
bool hashmap_remove(hashmap_t *hashmap, void *key)
Remove an entry from the hashmap.
hashmap_t * hashmap_create(hashmap_parameters_t *params)
Create a hashmap.
size_t hashmap_count(hashmap_t *hashmap)
Get the number of entries in this map.
void * hashmap_lookup(hashmap_t *hashmap, void *key)
Look up a key in a hashmap.
void * hashmap_insert(hashmap_t *hashmap, void *key)
Create an entry in a hashmap.
bool hashmap_iterate(hashmap_t *hashmap, hashmap_iteration_cb_t cb, void *ctx)
Iterate the hashmap.
#define DEFAULT_HASHMAP_BUCKETS
The default number of buckets in the hashmaps we create.
void hashmap_destroy(hashmap_t *hashmap)
Destroy a hashmap.
bool(* hashmap_iteration_cb_t)(void *, void *, void *)
Hashmap iteration callback function type.
Interface to utility string handling.
Hashmaps have chains of entries in buckets.
struct hashmap_entry_s * next
struct hashmap_entry_s ** prevptr
hashmap_value_destroy_t value_destroy
A function which when called will destroy a value object.
hashmap_value_alloc_t value_alloc
A function which when called will allocate a value object.
hashmap_key_hash_t key_hash
A function which when given a key will return its hash.
hashmap_key_clone_t key_clone
A function which when called will clone a key and give ownership of the returned object to the hashma...
hashmap_key_destroy_t key_destroy
A function which when called will destroy a key object.
hashmap_key_eq_t key_eq
A function to compare two keys and return if they are equal.
The content of a hashmap.
size_t entry_count
The number of entries in this map.
hashmap_parameters_t * params
The parameters to be used for this hashmap.
uint32_t bucket_count
The number of buckets in this map.
hashmap_entry_t ** buckets
The buckets for the hash chains.