Last active
December 29, 2024 17:43
-
-
Save xrombar/3b6b84883fd1fc49ba7bfd360ddc5c9a to your computer and use it in GitHub Desktop.
quick and lazy fnv1a hasher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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