mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-30 16:30:10 +01:00
hash_table: Add new hash_table_remove function.
To allow for the removal of a single element from a hash table.
This commit is contained in:
parent
d1500f8a19
commit
d4f239de6e
2 changed files with 21 additions and 0 deletions
|
|
@ -142,6 +142,23 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
|
|||
insert_at_head(& ht->buckets[bucket], & node->link);
|
||||
}
|
||||
|
||||
void
|
||||
hash_table_remove(struct hash_table *ht, const void *key)
|
||||
{
|
||||
const unsigned hash_value = (*ht->hash)(key);
|
||||
const unsigned bucket = hash_value % ht->num_buckets;
|
||||
struct node *node;
|
||||
|
||||
foreach(node, & ht->buckets[bucket]) {
|
||||
struct hash_node *hn = (struct hash_node *) node;
|
||||
|
||||
if ((*ht->compare)(hn->key, key) == 0) {
|
||||
remove_from_list(node);
|
||||
free(node);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned
|
||||
hash_table_string_hash(const void *key)
|
||||
|
|
|
|||
|
|
@ -94,6 +94,10 @@ extern void *hash_table_find(struct hash_table *ht, const void *key);
|
|||
extern void hash_table_insert(struct hash_table *ht, void *data,
|
||||
const void *key);
|
||||
|
||||
/**
|
||||
* Remove a specific element from a hash table.
|
||||
*/
|
||||
extern void hash_table_remove(struct hash_table *ht, const void *key);
|
||||
|
||||
/**
|
||||
* Compute hash value of a string
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue