From e1ceef73192f0300ff9b10ba9a16475fbebeaa5f Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 30 Aug 2024 17:01:28 +0300 Subject: proper repl, stylistic changes, removed trailing whitespace --- src/hashtable.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/hashtable.c') diff --git a/src/hashtable.c b/src/hashtable.c index 5ef1839..9f5d2e1 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -25,7 +25,7 @@ hashtable_t hashtable_create(size_t cap, hashtable_hash_func hash_func, hashtabl ht->size = 0; ERR_ERRNO_SET(hashtable_grow(ht, cap), goto fail); - + return ht; fail: hashtable_destroy(ht); @@ -35,15 +35,15 @@ fail: void hashtable_destroy(hashtable_t ht) { if(!ht) return; - + if(ht->table) { hashtable_for_each_item_safe(ht, item, i) { free(item); } - + free(ht->table); } - + free(ht); } @@ -66,7 +66,7 @@ int hashtable_insert(hashtable_t ht, void *key, void *data, void **prevkey, void struct hashtable_item *item, *prev; hashtable_find_item(ht, idx, key, &item, &prev); - + if(item) { if(prevkey) *prevkey = item->key; if(prevdata) *prevdata = item->data; @@ -74,49 +74,49 @@ int hashtable_insert(hashtable_t ht, void *key, void *data, void **prevkey, void item->data = data; return 0; } - + ERR_Z(item = malloc(sizeof(*item)), return -ENOMEM); - + item->key = key; item->data = data; item->next = NULL; hashtable_table_append_item(ht->table, idx, item); ht->size++; - + if(ht->size > (ht->cap * 3/4)) { return hashtable_grow(ht, 1 << ht->cap); } - + return 0; } int hashtable_query(hashtable_t ht, void *key, void **data) { size_t idx = HASH(ht, key); - + struct hashtable_item *item; ERR_NZ_RET(hashtable_find_item(ht, idx, key, &item, NULL)); *data = item->data; - + return 0; } int hashtable_delete(hashtable_t ht, void *key) { size_t idx = HASH(ht, key); - + struct hashtable_item *item, *prev; ERR_NZ_RET(hashtable_find_item(ht, idx, key, &item, &prev)); - + if(prev) prev->next = item->next; else ht->table[idx] = item->next; free(item); - + return 0; } @@ -137,7 +137,7 @@ static int hashtable_grow(hashtable_t ht, size_t cap) ht->table = new_table; ht->cap = cap; - + return 0; } @@ -153,7 +153,7 @@ static int hashtable_find_item(hashtable_t ht, size_t idx, void *key, struct has } if(prev) *prev = _item; } - + return -ENOENT; } -- cgit v1.2.3