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/set.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/shared/set.c') diff --git a/src/shared/set.c b/src/shared/set.c index 4b8c76feca..087d874598 100644 --- a/src/shared/set.c +++ b/src/shared/set.c @@ -50,3 +50,7 @@ bool set_contains(Set *s, void *value) { void *set_iterate(Set *s, Iterator *i) { return hashmap_iterate(MAKE_HASHMAP(s), i, NULL); } + +int set_reserve(Set *s, unsigned entries_add) { + return hashmap_reserve(MAKE_HASHMAP(s), entries_add); +} -- cgit v1.2.3-54-g00ecf