test_tdb_hash_functions: add distribution tests
[ruby-tdb.git] / Hash_Functions
blobc10ded7ed676d051ae71eeb6e00650ee0d112120
1 = Brief overview of hash functions supported by Ruby TDB
3 Ruby TDB supports several alternative hash functions in addition to the
4 defaults supported by TDB upstream.  Hash functions behave and perform
5 differently depending on the key and type of keys you use.  We support
6 several popular hash functions (and will accept patches to support
7 more).
9 Changing hash functions on an already-created database will cause
10 corruption, so don't do it.
12 == TDB Upstream Defaults
14 * the default hash use by TDB is based on the hash algorithm from gdbm.
15   You may specify this by passing explicitly to TDB.new:
16   <code>:hash => :default</code>
18 * the new default (available via TDB::INCOMPATIBLE_HASH) is the Jenkins
19   {lookup3 hash}[http://www.burtleburtle.net/bob/c/lookup3.c].
20   <code>:hash => :jenkins_lookup3</code>
22 == Murmur family
24 The {Murmur}[https://sites.google.com/site/murmurhash/] family of hashes
25 are supported by Ruby TDB.  MurmurHash3 will be supported as soon as it
26 becomes finalized.  Most of these are not endian-neutral so databases
27 are no compatible between machines of different endianness and were
28 designed with x86 and x86_64 in mind (they may crash or not work on
29 other architectures).
31 * :murmur2 - the simple and fast implementation
33 * :murmur2a - words of the author:
35       This is a variant of MurmurHash2 modified to use the
36       Merkle-Damgard construction. Bulk speed should be identical to
37       Murmur2, small-key speed will be 10%-20% slower due to the added
38       overhead at the end of the hash.
40       This variant fixes a minor issue where null keys were more likely to
41       collide with each other than expected, and also makes the algorithm
42       more amenable to incremental implementations. All other caveats from
43       MurmurHash2 still apply.
45 * :murmur2_aligned - a safer, but slower variant of :murmur2 designed
46   for platforms where unaligned 4-byte reads can crash the machine.
48 * :murmur2_neutral - endian/alignment-neutral version of the simple
49   implementation, half as fast according to the author.
51 * :murmur1 - simple and fast historical version
53 * :murmur1_aligned - according to the author, the performance of this
54   one should be as good or better than the simple version.
56 == FNV family
58 * :fnv1a - the recommended variant of the popular
59   {Fowler-Noll-Vo}[http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash_function]
60   hash function
62 == Bernstein hashes
64 * :djb3 - The hash currently favored by Bernstein.
65   See http://www.cse.yorku.ca/~oz/hash.html
67 * :djb2 - See http://www.cse.yorku.ca/~oz/hash.html