BLI: add DefaultHash specializations for StringRef and StringRefNull

This commit is contained in:
Jacques Lucke 2020-04-24 23:14:33 +02:00
parent 62f6255b47
commit ebe0d7ca5e
1 changed files with 25 additions and 5 deletions

View File

@ -30,6 +30,7 @@
#include <utility>
#include "BLI_math_base.h"
#include "BLI_string_ref.hh"
#include "BLI_utildefines.h"
namespace BLI {
@ -67,14 +68,33 @@ template<> struct DefaultHash<float> {
}
};
inline uint32_t hash_string(StringRef str)
{
uint32_t hash = 5381;
for (char c : str) {
hash = hash * 33 + c;
}
return hash;
}
template<> struct DefaultHash<std::string> {
uint32_t operator()(const std::string &value) const
{
uint32_t hash = 5381;
for (char c : value) {
hash = hash * 33 + c;
}
return hash;
return hash_string(value);
}
};
template<> struct DefaultHash<StringRef> {
uint32_t operator()(const StringRef &value) const
{
return hash_string(value);
}
};
template<> struct DefaultHash<StringRefNull> {
uint32_t operator()(const StringRefNull &value) const
{
return hash_string(value);
}
};