diff --git a/include/QF/hash.h b/include/QF/hash.h index 35bf23574..6f4ed1a9f 100644 --- a/include/QF/hash.h +++ b/include/QF/hash.h @@ -85,10 +85,11 @@ void *Hash_Find (hashtab_t *tab, const char *key); delete an element from a hash table: tab: the table to remove the element from key: the key string identifying the element to be deleted - returns 0 on success, -1 if the element could not be found. + returns a pointer to the element on success, 0 if the element could not + be found. Does /NOT/ call the free element function. That is the caller's responsibility. */ -int Hash_Del (hashtab_t *tab, const char *key); +void *Hash_Del (hashtab_t *tab, const char *key); #endif // __hash_h diff --git a/libs/util/hash.c b/libs/util/hash.c index bfd859b62..f3f443f98 100644 --- a/libs/util/hash.c +++ b/libs/util/hash.c @@ -157,22 +157,24 @@ Hash_Find (hashtab_t *tab, const char *key) return 0; } -int +void * Hash_Del (hashtab_t *tab, const char *key) { unsigned long h = hash (key); size_t ind = h % tab->tab_size; struct hashlink_s *lnk = tab->tab[ind]; + void *data; while (lnk) { if (strequal (key, tab->get_key (lnk->data, tab->user_data))) { + data = lnk->data; if (lnk->next) lnk->next->prev = lnk->prev; *lnk->prev = lnk->next; free (lnk); - return 0; + return data; } lnk = lnk->next; } - return -1; + return 0; }