From ec7253e743ed0f3e8a8a25eb78185b37e53af3cb Mon Sep 17 00:00:00 2001 From: Tiziano Bettio Date: Tue, 3 Dec 2024 10:20:41 +0100 Subject: [PATCH] Generate single header version Forgot to do the thing... --- soso.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/soso.c b/soso.c index 23ec5a7..c307b73 100644 --- a/soso.c +++ b/soso.c @@ -115,6 +115,15 @@ void sht_destroy(sht_t *sht); */ uint32_t sht_set(sht_t *sht, const void *key, int len, const void *item); +/** + * @brief Add or overwrite an item in the hashtable with a specific hash value. + * + * @param sht Pointer to the hashtable + * @param hash The hash value of the item + * @param item Pointer to the item + */ +void sht_set_by_hash(sht_t *sht, uint32_t hash, const void *item); + /** * @brief Get an item if present. * @@ -603,12 +612,16 @@ static uint32_t comp_key(const void *key, int len, uint32_t seed) { return k; } +void sht_set_by_hash(sht_t *sht, uint32_t hash, const void *item) { + if (insert(sht->table, hash, sht->capacity, item, sht->item_size) > 0) + ++(sht->size); +} + uint32_t sht_set(sht_t *sht, const void *key, int len, const void *element) { assert(sht != NULL); grow(sht); uint32_t hash = comp_key(key, len, sht->seed); - if (insert(sht->table, hash, sht->capacity, element, sht->item_size) > 0) - ++(sht->size); + sht_set_by_hash(sht, hash, element); return hash; }