Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
- template <class T>
- constexpr T fnv(LPCSTR _str, bool mode1a = false)
- {
- T hash, offset, prime;
- // Resolve the proper values for hashing
- switch (sizeof(T))
- {
- case 4:
- prime = 16777619ul;
- hash = offset = 2166136261ul;
- break;
- case 8:
- prime = 1099511628211ull;
- hash = offset = 14695981039346656037ull;
- break;
- }
- do hash = mode1a ? ((hash ^ static_cast<T>(*_str)) * prime) : ((hash * prime) ^ static_cast<T>(*_str));
- while (*_str++ != '\0');
- return hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement