mirror of
https://github.com/systemd/systemd.git
synced 2025-02-27 01:57:35 +03:00
hashmap: add hashmap_remove2() to remove item from hashtable and return both value and key
This commit is contained in:
parent
4f4f70361a
commit
c582a3b3e8
@ -582,6 +582,34 @@ void* hashmap_remove(Hashmap *h, const void *key) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* hashmap_remove2(Hashmap *h, const void *key, void **rkey) {
|
||||||
|
struct hashmap_entry *e;
|
||||||
|
unsigned hash;
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
if (!h) {
|
||||||
|
if (rkey)
|
||||||
|
*rkey = NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hash = bucket_hash(h, key);
|
||||||
|
e = hash_scan(h, hash, key);
|
||||||
|
if (!e) {
|
||||||
|
if (rkey)
|
||||||
|
*rkey = NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = e->value;
|
||||||
|
if (rkey)
|
||||||
|
*rkey = (void*) e->key;
|
||||||
|
|
||||||
|
remove_entry(h, e);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key, void *value) {
|
int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key, void *value) {
|
||||||
struct hashmap_entry *e;
|
struct hashmap_entry *e;
|
||||||
unsigned old_hash, new_hash;
|
unsigned old_hash, new_hash;
|
||||||
|
@ -69,6 +69,7 @@ void *hashmap_get(Hashmap *h, const void *key);
|
|||||||
void *hashmap_get2(Hashmap *h, const void *key, void **rkey);
|
void *hashmap_get2(Hashmap *h, const void *key, void **rkey);
|
||||||
bool hashmap_contains(Hashmap *h, const void *key);
|
bool hashmap_contains(Hashmap *h, const void *key);
|
||||||
void *hashmap_remove(Hashmap *h, const void *key);
|
void *hashmap_remove(Hashmap *h, const void *key);
|
||||||
|
void *hashmap_remove2(Hashmap *h, const void *key, void **rkey);
|
||||||
void *hashmap_remove_value(Hashmap *h, const void *key, void *value);
|
void *hashmap_remove_value(Hashmap *h, const void *key, void *value);
|
||||||
int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key, void *value);
|
int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key, void *value);
|
||||||
int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_key, void *value);
|
int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_key, void *value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user