Implement fast hash function

Hi everyone,

I have a project where I need to apply a hash function to some variables in a sequential way. That action will be done frequently so I need it to be as fast as possible but making sure that there are almost no collisions.

I´ve looked for a hash function in the standard library, but the std::hash is not what I´m looking for.

Does anyone know a library that I can use or an algorithm that I can implement with the performance that I want?

Thanks in advanced!
What are the types of the variables to be used in the hash?
They are all size_t
For very fast non-cryptographic hash functions look into:

Murmur3:
https://github.com/PeterScott/murmur3

CityHash:
https://github.com/google/cityhash

FNV64:
1
2
3
4
5
6
7
8
9
10
uint64_t fnv64(const uint8_t *pBuffer, const uint8_t *const pBufferEnd)
{
    const uint64_t MagicPrime = UINT64_C(0x00000100000001B3);
    uint64_t       Hash       = UINT64_C(0xCBF29CE484222325);
 
    for (; pBuffer < pBufferEnd; pBuffer++)
        Hash = (Hash ^ (*pBuffer)) * MagicPrime;

    return Hash;
}
Last edited on
Thanks for your help! These algorithms seem to be what I need.
Topic archived. No new replies allowed.