From 3f7474df0645224ce61fedcd908028f41971189e Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 16 May 2020 10:38:24 -0700 Subject: fix: linking errors associated to linking bins against all dependencies. partitioned more explictly now --- include/libn/macro/map.h | 68 +++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) (limited to 'include') diff --git a/include/libn/macro/map.h b/include/libn/macro/map.h index 37b7dfd..45eb745 100644 --- a/include/libn/macro/map.h +++ b/include/libn/macro/map.h @@ -25,25 +25,21 @@ static const double __ac_HASH_UPPER = 0.77; #define __ac_fsize(m) ((m) < 16 ? 1 : (m) >> 4) #define MAP_STRUCT_BODY(key_t, val_t) \ - mem·Allocator heap; \ - void *h; \ int32 n_buckets, size, n_occupied, upper_bound; \ int32 *flags; \ key_t *keys; \ val_t *vals; -#define MAP_MAKE(type) \ +#define MAP_MAKE(type, h, alloc) \ type *map; \ - map = heap.alloc((h), 1, sizeof(*map)); \ - map->heap = heap; \ - map->h = h; \ + map = alloc((h), 1, sizeof(*map)); \ return map -#define MAP_FREE(map) \ - map->heap.free(map->h, map->keys); \ - map->heap.free(map->h, map->flags); \ - map->heap.free(map->h, map->vals); \ - map->heap.free(map->h, map); +#define MAP_FREE(map, free, h) \ + free(h, map->keys); \ + free(h, map->flags); \ + free(h, map->vals); \ + free(h, map); #define MAP_RESET(map) \ if (map && map->flags) { \ @@ -51,28 +47,30 @@ static const double __ac_HASH_UPPER = 0.77; map->size = map->n_occupied = 0; \ } -#define MAP_GET(map, key, hashfunc, equalfunc) \ +#define MAP_GET(i, map, key, hashfunc, equalfunc ) \ + int32 k, last, mask, step; \ if (map->n_buckets) { \ - int32 k = 0; \ - int32 i = 0; \ - int32 last = 0; \ - int32 mask = 0; \ - int32 step = 0; \ + k = 0; \ + i = 0; \ + last = 0; \ + mask = 0; \ + step = 0; \ mask = map->n_buckets - 1; \ - k = hashfunc(key); \ - i = k & mask; \ + k = hashfunc(key); \ + i = k & mask; \ last = i; \ while (!__ac_isempty(map->flags, i) && \ (__ac_isdel(map->flags, i) || !equalfunc(map->keys[i], key))) { \ i = (i + (++step)) & mask; \ if (i == last) \ - return map->n_buckets; \ + i = map->n_buckets; \ } \ - return __ac_iseither(map->flags, i) ? map->n_buckets : i; \ + if (__ac_iseither(map->flags, i)) \ + i = map->n_buckets; \ } else \ - return 0; + i = 0; -#define MAP_GROW(map, key_t, val_t, new_n_buckets, hashfunc) \ +#define MAP_GROW(map, key_t, val_t, new_n_buckets, hashfunc, alloc, free, h) \ int32 *new_flags = nil; \ int32 j = 1; \ { \ @@ -83,25 +81,25 @@ static const double __ac_HASH_UPPER = 0.77; j = 0; \ else { \ new_flags = \ - map->heap.alloc(map->h, __ac_fsize(new_n_buckets), sizeof(int32)); \ + alloc(h, __ac_fsize(new_n_buckets), sizeof(int32)); \ if (!new_flags) return -1; \ memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(int32)); \ if (map->n_buckets < new_n_buckets) { /* expand */ \ key_t *new_keys = \ - map->heap.alloc(map->h, new_n_buckets, sizeof(key_t)); \ + alloc(h, new_n_buckets, sizeof(key_t)); \ if (!new_keys) { \ - map->heap.free(map->h, new_flags); \ + free(h, new_flags); \ return -1; \ } \ - map->heap.free(map->h, map->keys); \ + free(h, map->keys); \ map->keys = new_keys; \ val_t *new_vals = \ - map->heap.alloc(map->h, new_n_buckets, sizeof(val_t)); \ + alloc(h, new_n_buckets, sizeof(val_t)); \ if (!new_vals) { \ - map->heap.free(map->h, new_flags); \ + free(h, new_flags); \ return -1; \ } \ - map->heap.free(map->h, map->vals); \ + free(h, map->vals); \ map->vals = new_vals; \ } \ } \ @@ -143,15 +141,15 @@ static const double __ac_HASH_UPPER = 0.77; } \ } \ if (map->n_buckets > new_n_buckets) { /* shrink the hash table */ \ - key_t *new_keys = map->heap.alloc(map->h, new_n_buckets, sizeof(key_t)); \ - map->heap.free(map->h, map->keys); \ + key_t *new_keys = alloc(h, new_n_buckets, sizeof(key_t)); \ + free(h, map->keys); \ map->keys = new_keys; \ \ - val_t *new_vals = map->heap.alloc(map->h, new_n_buckets, sizeof(val_t)); \ - map->heap.free(map->h, map->vals); \ + val_t *new_vals = alloc(h, new_n_buckets, sizeof(val_t)); \ + free(h, map->vals); \ map->vals = new_vals; \ } \ - map->heap.free(map->h, map->flags); /* free the working space */ \ + free(h, map->flags); /* free the working space */ \ map->flags = new_flags; \ map->n_buckets = new_n_buckets; \ map->n_occupied = map->size; \ -- cgit v1.2.1