diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index 33fd8bbc..b054b679 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -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 {