mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 23:44:06 +00:00
hashtable: add remove2 to retrieve the value that was removed
This commit is contained in:
parent
d0ec3fb8f0
commit
3f2bf4d659
@ -213,7 +213,7 @@ void *git_hashtable_lookup(git_hashtable *self, const void *key)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int git_hashtable_remove(git_hashtable *self, const void *key)
|
||||
int git_hashtable_remove2(git_hashtable *self, const void *key, void **old_value)
|
||||
{
|
||||
int hash_id;
|
||||
git_hashtable_node *node;
|
||||
@ -223,6 +223,7 @@ int git_hashtable_remove(git_hashtable *self, const void *key)
|
||||
for (hash_id = 0; hash_id < GIT_HASHTABLE_HASHES; ++hash_id) {
|
||||
node = node_with_hash(self, key, hash_id);
|
||||
if (node->key && self->key_equal(key, node->key) == 0) {
|
||||
*old_value = node->value;
|
||||
node->key = NULL;
|
||||
node->value = NULL;
|
||||
self->key_count--;
|
||||
|
@ -42,7 +42,15 @@ git_hashtable *git_hashtable_alloc(size_t min_size,
|
||||
git_hash_ptr hash,
|
||||
git_hash_keyeq_ptr key_eq);
|
||||
void *git_hashtable_lookup(git_hashtable *h, const void *key);
|
||||
int git_hashtable_remove(git_hashtable *table, const void *key);
|
||||
int git_hashtable_remove2(git_hashtable *table, const void *key, void **old_value);
|
||||
|
||||
GIT_INLINE(int) git_hashtable_remove(git_hashtable *table, const void *key)
|
||||
{
|
||||
void *_unused;
|
||||
return git_hashtable_remove2(table, key, &_unused);
|
||||
}
|
||||
|
||||
|
||||
void git_hashtable_free(git_hashtable *h);
|
||||
void git_hashtable_clear(git_hashtable *h);
|
||||
int git_hashtable_merge(git_hashtable *self, git_hashtable *other);
|
||||
|
Loading…
Reference in New Issue
Block a user