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
This commit is contained in:
Axel Dörfler 2004-11-10 01:56:22 +00:00
parent 347759a7e7
commit 4f727c8fb6

View File

@ -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)
{