diff options
Diffstat (limited to 'src/hashtable.c')
-rw-r--r-- | src/hashtable.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/hashtable.c b/src/hashtable.c index 4006a8714..242a6fa1d 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -183,6 +183,37 @@ void *git_hashtable_lookup(git_hashtable *table, const void *key) return NULL; } +int git_hashtable_remove(git_hashtable *table, const void *key) +{ + git_hashtable_node *node, *prev_node; + uint32_t index, hash; + + assert(table); + + hash = table->hash(key); + index = (hash & table->size_mask); + node = table->nodes[index]; + + prev_node = NULL; + + while (node != NULL) { + if (node->hash == hash && table->key_equal(node->object, key)) { + if (prev_node == NULL) + table->nodes[index] = node->next; + else + prev_node->next = node->next; + + free(node); + return GIT_SUCCESS; + } + + prev_node = node; + node = node->next; + } + + return GIT_ENOTFOUND; +} + void git_hashtable_iterator_init(git_hashtable *table, git_hashtable_iterator *it) |