chiark / gitweb /
hashmap: return more information from resize_buckets()
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 14 Oct 2014 22:36:45 +0000 (00:36 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 23 Oct 2014 15:38:02 +0000 (17:38 +0200)
Return 0 if no resize was needed, 1 if successfully resized and
negative on error.

src/shared/hashmap.c

index 1c3a452899920c9ac5322863aec1c94db8f370bc..0b456411d525bd7afc30567e0543603bd2d5ebb5 100644 (file)
@@ -369,7 +369,7 @@ static struct hashmap_entry *hash_scan(Hashmap *h, unsigned hash, const void *ke
         return NULL;
 }
 
         return NULL;
 }
 
-static bool resize_buckets(Hashmap *h) {
+static int resize_buckets(Hashmap *h) {
         struct hashmap_entry **n, *i;
         unsigned m;
         uint8_t nkey[HASH_KEY_SIZE];
         struct hashmap_entry **n, *i;
         unsigned m;
         uint8_t nkey[HASH_KEY_SIZE];
@@ -377,7 +377,7 @@ static bool resize_buckets(Hashmap *h) {
         assert(h);
 
         if (_likely_(h->n_entries*4 < h->n_buckets*3))
         assert(h);
 
         if (_likely_(h->n_entries*4 < h->n_buckets*3))
-                return false;
+                return 0;
 
         /* Increase by four */
         m = (h->n_entries+1)*4-1;
 
         /* Increase by four */
         m = (h->n_entries+1)*4-1;
@@ -385,7 +385,7 @@ static bool resize_buckets(Hashmap *h) {
         /* If we hit OOM we simply risk packed hashmaps... */
         n = new0(struct hashmap_entry*, m);
         if (!n)
         /* If we hit OOM we simply risk packed hashmaps... */
         n = new0(struct hashmap_entry*, m);
         if (!n)
-                return false;
+                return -ENOMEM;
 
         /* Let's use a different randomized hash key for the
          * extension, so that people cannot guess what we are using
 
         /* Let's use a different randomized hash key for the
          * extension, so that people cannot guess what we are using
@@ -424,7 +424,7 @@ static bool resize_buckets(Hashmap *h) {
 
         memcpy(h->hash_key, nkey, HASH_KEY_SIZE);
 
 
         memcpy(h->hash_key, nkey, HASH_KEY_SIZE);
 
-        return true;
+        return 1;
 }
 
 static int __hashmap_put(Hashmap *h, const void *key, void *value, unsigned hash) {
 }
 
 static int __hashmap_put(Hashmap *h, const void *key, void *value, unsigned hash) {
@@ -432,7 +432,7 @@ static int __hashmap_put(Hashmap *h, const void *key, void *value, unsigned hash
 
         struct hashmap_entry *e;
 
 
         struct hashmap_entry *e;
 
-        if (resize_buckets(h))
+        if (resize_buckets(h) > 0)
                 hash = bucket_hash(h, key);
 
         if (h->from_pool)
                 hash = bucket_hash(h, key);
 
         if (h->from_pool)