Lines Matching refs:hmap

120 void init_tuple_hmap(tuple_hmap_t *hmap, uint32_t n) {  in init_tuple_hmap()  argument
131 hmap->data = alloc_rec_array(n); in init_tuple_hmap()
132 hmap->size = n; in init_tuple_hmap()
133 hmap->nelems = 0; in init_tuple_hmap()
134 hmap->ndeleted = 0; in init_tuple_hmap()
135 hmap->resize_threshold = (uint32_t) (n * TUPLE_HMAP_RESIZE_RATIO); in init_tuple_hmap()
136 hmap->cleanup_threshold = (uint32_t) (n * TUPLE_HMAP_CLEANUP_RATIO); in init_tuple_hmap()
153 void delete_tuple_hmap(tuple_hmap_t *hmap) { in delete_tuple_hmap() argument
157 tmp = hmap->data; in delete_tuple_hmap()
158 n = hmap->size; in delete_tuple_hmap()
166 hmap->data = NULL; in delete_tuple_hmap()
173 void reset_tuple_hmap(tuple_hmap_t *hmap) { in reset_tuple_hmap() argument
177 tmp = hmap->data; in reset_tuple_hmap()
178 n = hmap->size; in reset_tuple_hmap()
186 hmap->nelems = 0; in reset_tuple_hmap()
187 hmap->ndeleted = 0; in reset_tuple_hmap()
215 static void tuple_hmap_cleanup(tuple_hmap_t *hmap) { in tuple_hmap_cleanup() argument
220 n = hmap->size; in tuple_hmap_cleanup()
224 r = hmap->data[i]; in tuple_hmap_cleanup()
230 safe_free(hmap->data); in tuple_hmap_cleanup()
231 hmap->data = tmp; in tuple_hmap_cleanup()
232 hmap->ndeleted = 0; in tuple_hmap_cleanup()
239 static void tuple_hmap_extend(tuple_hmap_t *hmap) { in tuple_hmap_extend() argument
244 n = hmap->size; in tuple_hmap_extend()
255 r = hmap->data[i]; in tuple_hmap_extend()
261 safe_free(hmap->data); in tuple_hmap_extend()
262 hmap->data = tmp; in tuple_hmap_extend()
263 hmap->size = n2; in tuple_hmap_extend()
264 hmap->ndeleted = 0; in tuple_hmap_extend()
265 hmap->resize_threshold = (uint32_t) (n2 * TUPLE_HMAP_RESIZE_RATIO); in tuple_hmap_extend()
266 hmap->cleanup_threshold = (uint32_t) (n2 * TUPLE_HMAP_CLEANUP_RATIO); in tuple_hmap_extend()
279 tuple_hmap_rec_t *tuple_hmap_find(tuple_hmap_t *hmap, uint32_t n, int32_t key[]) { in tuple_hmap_find() argument
283 assert(n <= TUPLE_HMAP_MAX_ARITY && hmap->nelems < hmap->size in tuple_hmap_find()
284 && is_power_of_two(hmap->size)); in tuple_hmap_find()
287 mask = hmap->size - 1; in tuple_hmap_find()
291 r = hmap->data[i]; in tuple_hmap_find()
311 tuple_hmap_rec_t *tuple_hmap_get(tuple_hmap_t *hmap, uint32_t n, int32_t key[], bool *new) { in tuple_hmap_get() argument
315 assert(n <= TUPLE_HMAP_MAX_ARITY && hmap->nelems < hmap->size && in tuple_hmap_get()
316 is_power_of_two(hmap->size)); in tuple_hmap_get()
319 mask = hmap->size - 1; in tuple_hmap_get()
323 r = hmap->data[i]; in tuple_hmap_get()
336 r = hmap->data[j]; in tuple_hmap_get()
338 hmap->ndeleted --; in tuple_hmap_get()
347 assert(hmap->data[i] == NULL || hmap->data[i] == TUPLE_HMAP_DELETED); in tuple_hmap_get()
349 hmap->data[i] = r; in tuple_hmap_get()
350 hmap->nelems ++; in tuple_hmap_get()
351 if (hmap->nelems + hmap->ndeleted > hmap->resize_threshold) { in tuple_hmap_get()
352 tuple_hmap_extend(hmap); in tuple_hmap_get()
370 void tuple_hmap_add(tuple_hmap_t *hmap, uint32_t n, int32_t key[], int32_t val) { in tuple_hmap_add() argument
374 assert(tuple_hmap_find(hmap, n, key) == NULL); in tuple_hmap_add()
380 mask = hmap->size - 1; in tuple_hmap_add()
382 while (live_tuple_record(hmap->data[i])) { in tuple_hmap_add()
387 assert(hmap->data[i] == NULL || hmap->data[i] == TUPLE_HMAP_DELETED); in tuple_hmap_add()
388 if (hmap->data[i] == TUPLE_HMAP_DELETED) { in tuple_hmap_add()
389 hmap->ndeleted --; in tuple_hmap_add()
391 hmap->data[i] = r; in tuple_hmap_add()
392 hmap->nelems ++; in tuple_hmap_add()
393 if (hmap->nelems + hmap->ndeleted > hmap->resize_threshold) { in tuple_hmap_add()
394 tuple_hmap_extend(hmap); in tuple_hmap_add()
402 void tuple_hmap_erase(tuple_hmap_t *hmap, tuple_hmap_rec_t *r) { in tuple_hmap_erase() argument
405 assert(tuple_hmap_find(hmap, r->arity, r->key) == r); in tuple_hmap_erase()
407 mask = hmap->size - 1; in tuple_hmap_erase()
409 while (hmap->data[i] != r) { in tuple_hmap_erase()
416 hmap->data[i] = TUPLE_HMAP_DELETED; in tuple_hmap_erase()
417 hmap->nelems --; in tuple_hmap_erase()
418 hmap->ndeleted ++; in tuple_hmap_erase()
419 if (hmap->ndeleted > hmap->cleanup_threshold) { in tuple_hmap_erase()
420 tuple_hmap_cleanup(hmap); in tuple_hmap_erase()
432 void tuple_hmap_remove(tuple_hmap_t *hmap, uint32_t n, int32_t key[]) { in tuple_hmap_remove() argument
436 assert(n <= TUPLE_HMAP_MAX_ARITY && hmap->nelems < hmap->size && in tuple_hmap_remove()
437 is_power_of_two(hmap->size)); in tuple_hmap_remove()
440 mask = hmap->size - 1; in tuple_hmap_remove()
444 r = hmap->data[i]; in tuple_hmap_remove()
454 hmap->data[i] = TUPLE_HMAP_DELETED; in tuple_hmap_remove()
455 hmap->nelems --; in tuple_hmap_remove()
456 hmap->ndeleted ++; in tuple_hmap_remove()
457 if (hmap->ndeleted > hmap->cleanup_threshold) { in tuple_hmap_remove()
458 tuple_hmap_cleanup(hmap); in tuple_hmap_remove()
471 void tuple_hmap_gc(tuple_hmap_t *hmap, void *aux, tuple_hmap_keep_fun_t f) { in tuple_hmap_gc() argument
475 n = hmap->size; in tuple_hmap_gc()
477 r = hmap->data[i]; in tuple_hmap_gc()
481 hmap->data[i] = TUPLE_HMAP_DELETED; in tuple_hmap_gc()
482 hmap->nelems --; in tuple_hmap_gc()
483 hmap->ndeleted ++; in tuple_hmap_gc()
487 if (hmap->ndeleted > hmap->cleanup_threshold) { in tuple_hmap_gc()
488 tuple_hmap_cleanup(hmap); in tuple_hmap_gc()