Fastest hash function for a sparse key

1 day ago 3
ARTICLE AD BOX

I have a uint32_t key with 2-4 bits set, and I have a perfect hash map. Right now, with a python script, I brute force to find kMul such that all the keys are in separate locations. The keys are approx 8 bits apart. For my use case, every cycle counts.

Question: Is there a faster (in terms of number of cycles) on how to do this?

const uint64_t* lookup(uint32_t key) { const uint32_t idx = (key * kMul) >> kShift; if (__builtin_expect(kIndexData[idx] != key, false)) { return nullptr; } return kValuesData + idx * kValueWidth; }

Dumps of the keys: https://pastebin.com/EWe9Hdf5

Read Entire Article