diff options
author | Petr Machata <pmachata@redhat.com> | 2012-04-19 16:57:57 +0200 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-04-19 16:57:57 +0200 |
commit | 77fbb8ff4ba461c11af3678a0db7cf6a47738ff4 (patch) | |
tree | fd290ac8e079a45cc8beab0d80149a35e6208b0e /dict.c | |
parent | d2fc09dccfc18680209a918dc8cbcc1f75e41118 (diff) | |
download | ltrace-77fbb8ff4ba461c11af3678a0db7cf6a47738ff4.tar.gz |
Implement dict_remove
Diffstat (limited to 'dict.c')
-rw-r--r-- | dict.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -104,6 +104,29 @@ dict_enter(Dict *d, void *key, void *value) { } void * +dict_remove(Dict *d, void *key) +{ + assert(d != NULL); + debug(DEBUG_FUNCTION, "dict_remove(%p)", key); + + unsigned int hash = d->key2hash(key); + unsigned int bucketpos = hash % DICTTABLESIZE; + + struct dict_entry **entryp; + for (entryp = &d->buckets[bucketpos]; (*entryp) != NULL; + entryp = &(*entryp)->next) { + struct dict_entry *entry = *entryp; + if (hash != entry->hash) + continue; + if (d->key_cmp(key, entry->key) == 0) { + *entryp = entry->next; + return entry->value; + } + } + return NULL; +} + +void * dict_find_entry(Dict *d, const void *key) { unsigned int hash; |