EASTL
EASTL copied to clipboard
Hashing of fixed_string
Currently the eastl isn't capable of hashing fixed_strings by say putting them in a hash_map. The code for doing that is actually relatively simple if we do the same as string
template <typename T, int nodeCount, bool bEnableOverflow, typename OverflowAllocator>
struct hash<fixed_string<T, nodeCount, bEnableOverflow, OverflowAllocator>>
{
size_t operator()(const fixed_string<T, nodeCount, bEnableOverflow, OverflowAllocator>& x) const
{
const unsigned char* p = (const unsigned char*)x.c_str(); // To consider: limit p to at most 256 chars.
unsigned int c, result = 2166136261U; // We implement an FNV-like string hash.
while ((c = *p++) != 0) // Using '!=' disables compiler warnings.
result = (result * 16777619) ^ c;
return (size_t)result;
}
};
Does this look like a useful addition?