diff options
Diffstat (limited to 'src/common/libalgo')
-rw-r--r-- | src/common/libalgo/hashtbl.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/common/libalgo/hashtbl.c b/src/common/libalgo/hashtbl.c index f490632..f34c6d4 100644 --- a/src/common/libalgo/hashtbl.c +++ b/src/common/libalgo/hashtbl.c @@ -160,4 +160,17 @@ size_t hashtbl_count(hashtbl_t* ht) { return ht->nitems; } +bool hashtbl_change(hashtbl_t* ht, void* key, void* newval) { + size_t slot = SLOT_OF_HASH(ht->hf(key), ht->size); + + for (hashtbl_item_t *i = ht->items[slot]; i != 0; i = i->next) { + if (ht->ef(i->key, key)) { + i->val = newval; + return true; + } + } + + return false; +} + /* vim: set ts=4 sw=4 tw=0 noet :*/ |