From 4f727c8fb6fdd4cc4727ffe2f3c20406ec65c669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 10 Nov 2004 01:56:22 +0000 Subject: [PATCH] New function hash_remove_first() makes emptying a hash table much simpler. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9892 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/khash.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/kernel/core/khash.c b/src/kernel/core/khash.c index 82e21f7679..b923ca29e1 100644 --- a/src/kernel/core/khash.c +++ b/src/kernel/core/khash.c @@ -140,6 +140,27 @@ hash_remove(struct hash_table *table, void *_element) } +void * +hash_remove_first(struct hash_table *table, uint32 *_cookie) +{ + uint32 index; + + for (index = _cookie ? *_cookie : 0; index < table->table_size; index++) { + void *element = table->table[index]; + if (element != NULL) { + // remove the first element we find + table->table[index] = (struct hash_element *)NEXT(table, element); + table->num_elements--; + if (_cookie) + *_cookie = index; + return element; + } + } + + return NULL; +} + + void * hash_find(struct hash_table *table, void *searchedElement) {