add a hashtable implementation that supports O(1) removal
commitdfbbbd2c35efc60f11dcd79c5e96e55a34f83e8d
authorKarsten Blees <karsten.blees@gmail.com>
Thu, 14 Nov 2013 19:17:54 +0000 (14 20:17 +0100)
committerJohannes Schindelin <johannes.schindelin@gmx.de>
Sat, 10 May 2014 21:56:56 +0000 (10 16:56 -0500)
tree07139b70dd3170036e098e9218a3f77df606ba9e
parentc33e6c7c751e98cd68744421c86f1c9bdb83b136
add a hashtable implementation that supports O(1) removal

The existing hashtable implementation (in hash.[ch]) uses open addressing
(i.e. resolve hash collisions by distributing entries across the table).
Thus, removal is difficult to implement with less than O(n) complexity.
Resolving collisions of entries with identical hashes (e.g. via chaining)
is left to the client code.

Add a hashtable implementation that supports O(1) removal and is slightly
easier to use due to builtin entry chaining.

Supports all basic operations init, free, get, add, remove and iteration.

Also includes ready-to-use hash functions based on the public domain FNV-1
algorithm (http://www.isthe.com/chongo/tech/comp/fnv).

The per-entry data structure (hashmap_entry) is piggybacked in front of
the client's data structure to save memory. See test-hashmap.c for usage
examples.

The hashtable is resized by a factor of four when 80% full. With these
settings, average memory consumption is about 2/3 of hash.[ch], and
insertion is about twice as fast due to less frequent resizing.

Lookups are also slightly faster, because entries are strictly confined to
their bucket (i.e. no data of other buckets needs to be traversed).

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/technical/api-hashmap.txt [new file with mode: 0644]
Makefile
hashmap.c [new file with mode: 0644]
hashmap.h [new file with mode: 0644]
t/t0011-hashmap.sh [new file with mode: 0755]
test-hashmap.c [new file with mode: 0644]