summaryrefslogtreecommitdiff
path: root/src/shared/hashmap.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-25 01:19:24 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-25 01:24:44 +0200
commitd99ae53a7327e1520ea4b9a3408c2d7f938c4b37 (patch)
tree52754f0a756cc93c32099dad6f76ac93779626df /src/shared/hashmap.c
parentcae356ad49b505a5172d4dbb830d7ec8f32a9953 (diff)
journal: properly serialize fields with multiple values into JSON
This now matches the JSON serialization spec from: http://www.freedesktop.org/wiki/Software/systemd/json
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;