From 4531818f12221fdedba9f6f4913d22228628328c Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Sat, 25 Oct 2014 18:18:26 -0400 Subject: hashmap: introduce hashmap_reserve() With the current hashmap implementation that uses chaining, placing a reservation can serve two purposes: - To optimize putting of entries if the number of entries to put is known. The reservation allocates buckets, so later resizing can be avoided. - To avoid having very long bucket chains after using hashmap_move(_one). In an alternative hashmap implementation it will serve an additional purpose: - To guarantee a subsequent hashmap_move(_one) will not fail with -ENOMEM (this never happens in the current implementation). Signed-off-by: Anthony G. Basile --- src/shared/hashmap.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/shared/hashmap.h') diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h index 53b04eb033..22bda37437 100644 --- a/src/shared/hashmap.h +++ b/src/shared/hashmap.h @@ -65,6 +65,7 @@ int hashmap_put(Hashmap *h, const void *key, void *value); void *hashmap_get(Hashmap *h, const void *key); void *hashmap_get2(Hashmap *h, const void *key, void **rkey); bool hashmap_contains(Hashmap *h, const void *key); +int hashmap_reserve(Hashmap *h, unsigned entries_add); unsigned hashmap_size(Hashmap *h) _pure_; -- cgit v1.2.3-54-g00ecf