Skip to content

Commit

Permalink
Generate single header version
Browse files Browse the repository at this point in the history
Forgot to do the thing...
  • Loading branch information
tcdude committed Dec 3, 2024
1 parent a840325 commit ec7253e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions soso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ec7253e

Please sign in to comment.