diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-06-23 11:46:02 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-06-23 11:47:08 +0530 |
commit | a3c16056c2ea8083db39054271f1118aed37ccc3 (patch) | |
tree | b65ad6d8fe4e603cb000ce89501a052df75a4a99 /src/htab.c | |
parent | 4740b89e88dff04361da7f7f3bd9e823fd75d5b2 (diff) |
htab: clean up
Diffstat (limited to 'src/htab.c')
-rw-r--r-- | src/htab.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1,7 +1,7 @@ -/* since hsearch_r does not support deletions dirctly, this is an abstraction on - * top of it with support for deletions, for this to work properly we have to - * strdup the key, this is not a big issue for 100k drv_path strings, it's - * either this or pulling in a external library +/* since hsearch_r does not support deletions dirctly (gotta go fast), this is + * an abstraction on top of it with support for deletions, for this to work + * properly we have to strdup the key, this is not a big issue for 100k drv_path + * strings, it's either this or pulling in an external library */ #include <errno.h> @@ -11,8 +11,6 @@ #include "htab.h" #include "util.h" -#define MAX_NIX_PKG_COUNT 200000 - static int htab_keys_insert(struct htab *htab, char *key); static int htab_keys_insert(struct htab *htab, char *key) @@ -97,7 +95,7 @@ int htab_delete(struct htab *htab, const char *key) return htab_enter(htab, key, NULL); } -int htab_init(struct htab **htab) +int htab_init(size_t nel, struct htab **htab) { int ret; struct htab *h; @@ -115,7 +113,7 @@ int htab_init(struct htab **htab) goto out_free_h; } - ret = hcreate_r(MAX_NIX_PKG_COUNT, h->table); + ret = hcreate_r(nel, h->table); if (ret == 0) { print_err("%s", strerror(errno)); ret = -errno; @@ -143,8 +141,10 @@ void htab_free(struct htab *htab) { for (size_t i = 0; i < htab->key_filled; i++) free(htab->keys[i]); - free(htab->keys); + + hdestroy_r(htab->table); free(htab->table); + free(htab); } |