Skip to content

Instantly share code, notes, and snippets.

View leidegre's full-sized avatar

John Leidegren leidegre

View GitHub Profile
@dwilliamson
dwilliamson / PerfectHash.cpp
Last active January 24, 2021 13:47
Trivial perfect hash generator that uses only a single array for runtime lookup with next to no ALU. Very good for small table sizes (e.g. < 128). Very bad for larger table sizes. This has been quickly "STL-ified" to remove use of my own containers.
uint32_t NextPow2(uint32_t v)
{
v--;
v |= (v >> 1);
v |= (v >> 2);
v |= (v >> 4);
v |= (v >> 8);
v |= (v >> 16);
v++;