} hash_node_t;
-size_t _util_hthash(hash_table_t *ht, const char *key) {
+size_t util_hthash(hash_table_t *ht, const char *key) {
uint64_t val = 0;
size_t len = strlen(key);
size_t itr = 0;
return hashtable;
}
-void util_htset(hash_table_t *ht, const char *key, void *value) {
- size_t bin = 0;
+void util_htseth(hash_table_t *ht, const char *key, size_t bin, void *value) {
hash_node_t *newnode = NULL;
hash_node_t *next = NULL;
hash_node_t *last = NULL;
- bin = _util_hthash(ht, key);
next = ht->table[bin];
while (next && next->key && strcmp(key, next->key) > 0)
last = next, next = next->next;
/* already in table, do a replace */
- if (next && next->key && !strcmp(key, next->key) == 0) {
+ if (next && next->key && strcmp(key, next->key) == 0) {
next->value = value;
} else {
/* not found, grow a pair man :P */
}
}
-void *util_htget(hash_table_t *ht, const char *key) {
- size_t bin = _util_hthash(ht, key);
+void util_htset(hash_table_t *ht, const char *key, void *value) {
+ util_htseth(ht, key, util_hthash(ht, key), value);
+}
+
+void *util_htgeth(hash_table_t *ht, const char *key, size_t bin) {
hash_node_t *pair = ht->table[bin];
while (pair && pair->key && strcmp(key, pair->key) > 0)
return pair->value;
}
+void *util_htget(hash_table_t *ht, const char *key) {
+ return util_htgeth(ht, key, util_hthash(ht, key));
+}
+
/*
* Free all allocated data in a hashtable, this is quite the amount
* of work.