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:
@ -598,6 +598,35 @@ public:
|
|||||||
static plString Fill(size_t count, char c);
|
static plString Fill(size_t count, char c);
|
||||||
|
|
||||||
public:
|
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. */
|
/** Functor which compares two strings case-insensitively for sorting. */
|
||||||
struct less_i
|
struct less_i
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user