mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-20 01:11:18 +00:00
slight api change: Hash_Del now returns a pointer to the element deleted, or
null if the element was not found, rather than 0 and -1 respectively.
This commit is contained in:
parent
03c0216dde
commit
6cda415f06
2 changed files with 8 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue