Return 0 if no resize was needed, 1 if successfully resized and
negative on error.
-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];
assert(h);
if (_likely_(h->n_entries*4 < h->n_buckets*3))
assert(h);
if (_likely_(h->n_entries*4 < h->n_buckets*3))
/* Increase by four */
m = (h->n_entries+1)*4-1;
/* Increase by four */
m = (h->n_entries+1)*4-1;
/* 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)
/* 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
memcpy(h->hash_key, nkey, HASH_KEY_SIZE);
memcpy(h->hash_key, nkey, HASH_KEY_SIZE);
}
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) {
+ if (resize_buckets(h) > 0)
hash = bucket_hash(h, key);
if (h->from_pool)
hash = bucket_hash(h, key);
if (h->from_pool)