1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

plString Hash for unordered containers

This commit is contained in:
2013-12-29 22:48:47 -05:00
committed by Michael Hansen
parent d7fdf10455
commit 249f26c53f

View File

@ -598,6 +598,35 @@ public:
static plString Fill(size_t count, char c);
public:
/** Functor that hashes a string for unordered containers.
* \note The hash is case sensitive.
*/
struct hash
{
size_t operator()(const plString& str) const
{
uint32_t hash = 0;
for (size_t i = 0; i < str.GetSize(); ++i) {
hash += str.CharAt(i);
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
};
/** Functor that hashes a string for unordered containers.
* \remarks This returns the hash of the lower-case variant of the string.
*/
struct hash_i : hash
{
size_t operator()(const plString& str) const
{ return hash::operator()(str.ToLower()); }
};
/** Functor which compares two strings case-insensitively for sorting. */
struct less_i
{