summaryrefslogtreecommitdiff
path: root/src/shared/hashmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/hashmap.c')
-rw-r--r--src/shared/hashmap.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/shared/hashmap.c b/src/shared/hashmap.c
index 26a4eff07f..ef78070f4c 100644
--- a/src/shared/hashmap.c
+++ b/src/shared/hashmap.c
@@ -328,7 +328,8 @@ int hashmap_put(Hashmap *h, const void *key, void *value) {
hash = h->hash_func(key) % NBUCKETS;
- if ((e = hash_scan(h, hash, key))) {
+ e = hash_scan(h, hash, key);
+ if (e) {
if (e->value == value)
return 0;
@@ -359,8 +360,8 @@ int hashmap_replace(Hashmap *h, const void *key, void *value) {
assert(h);
hash = h->hash_func(key) % NBUCKETS;
-
- if ((e = hash_scan(h, hash, key))) {
+ e = hash_scan(h, hash, key);
+ if (e) {
e->key = key;
e->value = value;
return 0;
@@ -369,6 +370,21 @@ int hashmap_replace(Hashmap *h, const void *key, void *value) {
return hashmap_put(h, key, value);
}
+int hashmap_update(Hashmap *h, const void *key, void *value) {
+ struct hashmap_entry *e;
+ unsigned hash;
+
+ assert(h);
+
+ hash = h->hash_func(key) % NBUCKETS;
+ e = hash_scan(h, hash, key);
+ if (!e)
+ return -ENOENT;
+
+ e->value = value;
+ return 0;
+}
+
void* hashmap_get(Hashmap *h, const void *key) {
unsigned hash;
struct hashmap_entry *e;
@@ -384,6 +400,24 @@ void* hashmap_get(Hashmap *h, const void *key) {
return e->value;
}
+void* hashmap_get2(Hashmap *h, const void *key, void **key2) {
+ unsigned hash;
+ struct hashmap_entry *e;
+
+ if (!h)
+ return NULL;
+
+ hash = h->hash_func(key) % NBUCKETS;
+ e = hash_scan(h, hash, key);
+ if (!e)
+ return NULL;
+
+ if (key2)
+ *key2 = (void*) e->key;
+
+ return e->value;
+}
+
bool hashmap_contains(Hashmap *h, const void *key) {
unsigned hash;