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; }