aboutsummaryrefslogtreecommitdiff
path: root/dict.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-04-19 16:57:57 +0200
committerPetr Machata <pmachata@redhat.com>2012-04-19 16:57:57 +0200
commit77fbb8ff4ba461c11af3678a0db7cf6a47738ff4 (patch)
treefd290ac8e079a45cc8beab0d80149a35e6208b0e /dict.c
parentd2fc09dccfc18680209a918dc8cbcc1f75e41118 (diff)
downloadltrace-77fbb8ff4ba461c11af3678a0db7cf6a47738ff4.tar.gz
Implement dict_remove
Diffstat (limited to 'dict.c')
-rw-r--r--dict.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/dict.c b/dict.c
index d7e14db..b32ef8e 100644
--- a/dict.c
+++ b/dict.c
@@ -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;