I'm doing some more C++ experimentation, and I'm pleased to present to you a hashing function that is:
- Windows-only 1
- Case insensitive, so "Hello World!" and "HeLlo WoRld!" both result in the same hash value
- 16-bit precision because even though the Windows function returns a 32-bit integer, the upper 4 bytes are always 0x0010
But hey, no external dependencies! All you have to do to use this function is include oleauto.h and link against OleAut32.lib 😄2
#include <oleauto.h>
uint16_t HashCaseInsensitive(std::string_view name)
{
return ::LHashValOfNameSysA(SYS_WIN64, LOCALE_SYSTEM_DEFAULT, name.data()) & 0xFFFF;
}
-
There's a
SYS_MACas well for some curséd reason. -
You probably don't want to use this in production.
