Skip to content

Instantly share code, notes, and snippets.

@xrombar
Last active December 29, 2024 17:43
Show Gist options
  • Select an option

  • Save xrombar/3b6b84883fd1fc49ba7bfd360ddc5c9a to your computer and use it in GitHub Desktop.

Select an option

Save xrombar/3b6b84883fd1fc49ba7bfd360ddc5c9a to your computer and use it in GitHub Desktop.
quick and lazy fnv1a hasher
template <typename T>
constexpr auto hash_ex( const T* buf, BOOL upper ) {
ULONG hash = 0x811C9DC5;
while ( *buf ) {
auto chr = static_cast<ULONG>( *buf++ );
if ( upper ) {
//
// uppercase
//
if ( chr >= 'a' && chr <= 'z' ) {
chr -= 32;
}
}
hash ^= chr;
hash *= 0x01000193;
}
return hash;
}
template <typename T>
constexpr auto hash( const T* buf ) {
return hash_ex<T>( buf, TRUE );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment