Fast hashtable
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Tue Feb 28 10:38:55 PST 2017
On Tuesday, 28 February 2017 at 17:57:14 UTC, Andrei Alexandrescu
wrote:
> This is of possible interest:
> https://probablydance.com/2017/02/26/i-wrote-the-fastest-hashtable/ -- Andrei
> But let’s say you know that your hash function returns numbers
> that are well distributed and that you’re rarely going to get
> hash collisions even if you use powers of two.
In which case you don't need powers of 2 either.
ucent h = hash64(key);
ulong slot = (h * slotCount) >> 64;
And you get what you want, with no constraint on the number of
slots. Note that on most architectures, this actually lowers to
one mulhi operation, which is typically 3 cycles.
More information about the Digitalmars-d
mailing list