Lines Matching refs:hash_map

59     hash_map_t *hash_map = osi_calloc(sizeof(hash_map_t));  in hash_map_new_internal()  local
60 if (hash_map == NULL) { in hash_map_new_internal()
64 hash_map->hash_fn = hash_fn; in hash_map_new_internal()
65 hash_map->key_fn = key_fn; in hash_map_new_internal()
66 hash_map->data_fn = data_fn; in hash_map_new_internal()
67 hash_map->keys_are_equal = equality_fn ? equality_fn : default_key_equality; in hash_map_new_internal()
69 hash_map->num_bucket = num_bucket; in hash_map_new_internal()
70 hash_map->bucket = osi_calloc(sizeof(hash_map_bucket_t) * num_bucket); in hash_map_new_internal()
71 if (hash_map->bucket == NULL) { in hash_map_new_internal()
72 osi_free(hash_map); in hash_map_new_internal()
75 return hash_map; in hash_map_new_internal()
88 void hash_map_free(hash_map_t *hash_map) in hash_map_free() argument
90 if (hash_map == NULL) { in hash_map_free()
93 hash_map_clear(hash_map); in hash_map_free()
94 osi_free(hash_map->bucket); in hash_map_free()
95 osi_free(hash_map); in hash_map_free()
115 bool hash_map_has_key(const hash_map_t *hash_map, const void *key) in hash_map_has_key() argument
117 assert(hash_map != NULL); in hash_map_has_key()
119 hash_index_t hash_key = hash_map->hash_fn(key) % hash_map->num_bucket; in hash_map_has_key()
120 list_t *hash_bucket_list = hash_map->bucket[hash_key].list; in hash_map_has_key()
126 bool hash_map_set(hash_map_t *hash_map, const void *key, void *data) in hash_map_set() argument
128 assert(hash_map != NULL); in hash_map_set()
131 hash_index_t hash_key = hash_map->hash_fn(key) % hash_map->num_bucket; in hash_map_set()
133 if (hash_map->bucket[hash_key].list == NULL) { in hash_map_set()
134 hash_map->bucket[hash_key].list = list_new_internal(bucket_free_); in hash_map_set()
135 if (hash_map->bucket[hash_key].list == NULL) { in hash_map_set()
139 list_t *hash_bucket_list = hash_map->bucket[hash_key].list; in hash_map_set()
149 hash_map->hash_size++; in hash_map_set()
158 hash_map_entry->hash_map = hash_map; in hash_map_set()
163 bool hash_map_erase(hash_map_t *hash_map, const void *key) in hash_map_erase() argument
165 assert(hash_map != NULL); in hash_map_erase()
167 hash_index_t hash_key = hash_map->hash_fn(key) % hash_map->num_bucket; in hash_map_erase()
168 list_t *hash_bucket_list = hash_map->bucket[hash_key].list; in hash_map_erase()
175 hash_map->hash_size--; in hash_map_erase()
177 if(list_is_empty(hash_map->bucket[hash_key].list)) { in hash_map_erase()
178 list_free(hash_map->bucket[hash_key].list); in hash_map_erase()
179 hash_map->bucket[hash_key].list = NULL; in hash_map_erase()
185 void *hash_map_get(const hash_map_t *hash_map, const void *key) in hash_map_get() argument
187 assert(hash_map != NULL); in hash_map_get()
189 hash_index_t hash_key = hash_map->hash_fn(key) % hash_map->num_bucket; in hash_map_get()
190 list_t *hash_bucket_list = hash_map->bucket[hash_key].list; in hash_map_get()
200 void hash_map_clear(hash_map_t *hash_map) in hash_map_clear() argument
202 assert(hash_map != NULL); in hash_map_clear()
204 for (hash_index_t i = 0; i < hash_map->num_bucket; i++) { in hash_map_clear()
205 if (hash_map->bucket[i].list == NULL) { in hash_map_clear()
208 list_free(hash_map->bucket[i].list); in hash_map_clear()
209 hash_map->bucket[i].list = NULL; in hash_map_clear()
213 void hash_map_foreach(hash_map_t *hash_map, hash_map_iter_cb callback, void *context) in hash_map_foreach() argument
215 assert(hash_map != NULL); in hash_map_foreach()
218 for (hash_index_t i = 0; i < hash_map->num_bucket; ++i) { in hash_map_foreach()
219 if (hash_map->bucket[i].list == NULL) { in hash_map_foreach()
222 for (const list_node_t *iter = list_begin(hash_map->bucket[i].list); in hash_map_foreach()
223 iter != list_end(hash_map->bucket[i].list); in hash_map_foreach()
237 const hash_map_t *hash_map = hash_map_entry->hash_map; in bucket_free_() local
239 if (hash_map->key_fn) { in bucket_free_()
240 hash_map->key_fn((void *)hash_map_entry->key); in bucket_free_()
242 if (hash_map->data_fn) { in bucket_free_()
243 hash_map->data_fn(hash_map_entry->data); in bucket_free_()
260 if (hash_map_entry->hash_map->keys_are_equal(hash_map_entry->key, key)) { in find_bucket_entry_()