From 9d48d5b7d48ad23e23eae02feae69bdc5ae80c8e Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 7 Dec 2014 22:10:16 +0100 Subject: [PATCH] Add an explicit hash_delete() function. --- src/hash.c | 7 +++++++ src/hash.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/hash.c b/src/hash.c index 8fb9ca69..91fc3d67 100644 --- a/src/hash.c +++ b/src/hash.c @@ -91,6 +91,13 @@ void *hash_search_or_insert(hash_t *hash, const void *key, const void *value) { return NULL; } +/* Deleting */ + +void hash_delete(hash_t *hash, const void *key) { + uint32_t i = modulo(hash_function(key, hash->size), hash->n); + hash->values[i] = NULL; +} + /* Utility functions */ void hash_clear(hash_t *hash) { diff --git a/src/hash.h b/src/hash.h index 83ed6aff..30a15fb2 100644 --- a/src/hash.h +++ b/src/hash.h @@ -31,6 +31,7 @@ extern hash_t *hash_alloc(size_t n, size_t size) __attribute__ ((__malloc__)); extern void hash_free(hash_t *); extern void hash_insert(hash_t *, const void *key, const void *value); +extern void hash_delete(hash_t *, const void *key); extern void *hash_search(const hash_t *, const void *key); extern void *hash_search_or_insert(hash_t *, const void *key, const void *value); -- 2.20.1