fix some lint warnings in Hash.h

This commit is contained in:
Mathias Agopian
2019-08-12 11:09:24 -07:00
committed by Mathias Agopian
parent 5df53f733e
commit eac2ad7e05
2 changed files with 31 additions and 23 deletions
+8 -8
View File
@@ -90,14 +90,14 @@ private:
friend size_t hash_value(TextureKey const& k) {
size_t seed = 0;
utils::hash::hash_combine(seed, k.target);
utils::hash::hash_combine(seed, k.levels);
utils::hash::hash_combine(seed, k.format);
utils::hash::hash_combine(seed, k.samples);
utils::hash::hash_combine(seed, k.width);
utils::hash::hash_combine(seed, k.height);
utils::hash::hash_combine(seed, k.depth);
utils::hash::hash_combine(seed, k.usage);
utils::hash::combine_fast(seed, k.target);
utils::hash::combine_fast(seed, k.levels);
utils::hash::combine_fast(seed, k.format);
utils::hash::combine_fast(seed, k.samples);
utils::hash::combine_fast(seed, k.width);
utils::hash::combine_fast(seed, k.height);
utils::hash::combine_fast(seed, k.depth);
utils::hash::combine_fast(seed, k.usage);
return seed;
}
};
+23 -15
View File
@@ -23,39 +23,47 @@
namespace utils {
namespace hash {
inline uint32_t murmur3(const uint32_t* key, size_t wordCount, uint32_t seed) {
inline uint32_t murmur3(const uint32_t* key, size_t wordCount, uint32_t seed) noexcept {
uint32_t h = seed;
size_t i = wordCount;
do {
uint32_t k = *key++;
k *= 0xcc9e2d51;
k = (k << 15) | (k >> 17);
k *= 0x1b873593;
k *= 0xcc9e2d51u;
k = (k << 15u) | (k >> 17u);
k *= 0x1b873593u;
h ^= k;
h = (h << 13) | (h >> 19);
h = (h * 5) + 0xe6546b64;
h = (h << 13u) | (h >> 19u);
h = (h * 5u) + 0xe6546b64u;
} while (--i);
h ^= wordCount;
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
h ^= h >> 16u;
h *= 0x85ebca6bu;
h ^= h >> 13u;
h *= 0xc2b2ae35u;
h ^= h >> 16u;
return h;
}
template<typename T>
struct MurmurHashFn {
uint32_t operator()(const T& key) const {
static_assert(0 == (sizeof(key) & 3), "Hashing requires a size that is a multiple of 4.");
uint32_t operator()(const T& key) const noexcept {
static_assert(0 == (sizeof(key) & 3u), "Hashing requires a size that is a multiple of 4.");
return murmur3((const uint32_t*) &key, sizeof(key) / 4, 0);
}
};
// combines two hashes together
template<class T>
inline void hash_combine(size_t& seed, const T& v) {
inline void combine(size_t& seed, const T& v) noexcept {
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6u) + (seed >> 2u);
seed ^= hasher(v) + 0x9e3779b9u + (seed << 6u) + (seed >> 2u);
}
// combines two hashes together, faster but less good
template<class T>
inline void combine_fast(size_t& seed, const T& v) noexcept {
std::hash<T> hasher;
seed ^= hasher(v) << 1u;
}
} // namespace hash