Fast hashtable

deadalnix via Digitalmars-d digitalmars-d at
Tue Feb 28 10:38:55 PST 2017

On Tuesday, 28 February 2017 at 17:57:14 UTC, Andrei Alexandrescu 
> This is of possible interest: 
> -- 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