chiark / gitweb /
hashmap: introduce hashmap_reserve()
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 14 Oct 2014 21:35:24 +0000 (23:35 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 23 Oct 2014 15:38:02 +0000 (17:38 +0200)
commite4c691b59db60ef2e6d8e64766d6ae02cd0dd457
treef6af93bdc6599e642099d3f9fc3a3b3e4ca2aee1
parent9700d6980f7c212b10a69399e6430b82a6f45587
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).
src/shared/hashmap.c
src/shared/hashmap.h
src/shared/set.c
src/shared/set.h