🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

ELF for 64bits

Started by
2 comments, last by Alundra 3 years, 1 month ago

Hi everybody,
Here is the classical world wide used ELF:

size_t Hash(const String& key)
{
    UInt32 hash = 0;
    for (size_t i = 0; i < key.GetLength(); ++i)
    {
        hash = (hash << 4) + key[i];
        const UInt32 g = hash & 0xF0000000;
        if (g != 0)
            hash ^= g >> 24;
        hash &= ~g;
    }
    return hash;
}

The problem is it's a 32bits algorithm which doesn't fit size_t for 64bits.
I tried to search information for a proper 64bits ELF hashing but could not find information.
Any help to understand how to have a proper 64bits ELF hashing would be very helpful.
Thanks a lot!

Advertisement

What is your usecase for a 64bit hashing algorithm and why does it matter if it doesn't fill an entire size_t?

It's mostly for learning purpose about what would be the best default approach.
But your comment makes also sense, ELF 32 bits will not block any working usage for a full range.
Maybe then the conclusion is ELF 32 bits is the best default hash for string for 32 bits and 64 bits.

This topic is closed to new replies.

Advertisement