diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-10-14 23:35:24 +0200 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-10-23 17:38:02 +0200 |
commit | e4c691b59db60ef2e6d8e64766d6ae02cd0dd457 (patch) | |
tree | f6af93bdc6599e642099d3f9fc3a3b3e4ca2aee1 /src/shared/hashmap.h | |
parent | 9700d6980f7c212b10a69399e6430b82a6f45587 (diff) |
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).
Diffstat (limited to 'src/shared/hashmap.h')
-rw-r--r-- | src/shared/hashmap.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/shared/hashmap.h b/src/shared/hashmap.h index 9789ad77ba..e0ff26c006 100644 --- a/src/shared/hashmap.h +++ b/src/shared/hashmap.h @@ -156,6 +156,10 @@ int hashmap_merge(Hashmap *h, Hashmap *other); static inline int ordered_hashmap_merge(OrderedHashmap *h, OrderedHashmap *other) { return hashmap_merge((Hashmap*) h, (Hashmap*) other); } +int hashmap_reserve(Hashmap *h, unsigned entries_add); +static inline int ordered_hashmap_reserve(OrderedHashmap *h, unsigned entries_add) { + return hashmap_reserve((Hashmap*) h, entries_add); +} void hashmap_move(Hashmap *h, Hashmap *other); static inline void ordered_hashmap_move(OrderedHashmap *h, OrderedHashmap *other) { hashmap_move((Hashmap*) h, (Hashmap*) other); |