Added Murmur3_64. (#364)

This commit is contained in:
Branimir Karadžić
2026-01-22 21:24:41 -08:00
committed by GitHub
parent d8d7d13c85
commit ef9c17cf3d
4 changed files with 312 additions and 34 deletions

View File

@@ -136,6 +136,36 @@ namespace bx
uint8_t m_count;
};
/// 64-bit non-cryptographic multiply and rotate hash.
class HashMurmur3_64
{
public:
///
void begin(uint64_t _seed = 0);
///
void add(const void* _data, int32_t _len);
///
void add(const char* _data);
///
void add(const StringView& _data);
///
template<typename Ty>
void add(const Ty& _data);
///
uint64_t end();
private:
uint64_t m_hash[2];
uint32_t m_size;
uint8_t m_tail[16];
uint8_t m_count;
};
///
template<typename HashT>
uint32_t hash(const void* _data, uint32_t _size);

View File

@@ -124,6 +124,33 @@ namespace bx
add(&_data, sizeof(Ty) );
}
inline void HashMurmur3_64::begin(uint64_t _seed)
{
BX_UNUSED(m_tail);
m_hash[0] = _seed;
m_hash[1] = _seed;
m_size = 0;
m_count = 0;
}
inline void HashMurmur3_64::add(const char* _data)
{
return add(StringView(_data) );
}
inline void HashMurmur3_64::add(const StringView& _data)
{
return add(_data.getPtr(), _data.getLength() );
}
template<typename Ty>
inline void HashMurmur3_64::add(const Ty& _data)
{
static_assert(isTriviallyCopyable<Ty>(), "Ty must be trivially copyable type.");
add(&_data, sizeof(Ty) );
}
template<typename HashT>
inline uint32_t hash(const void* _data, uint32_t _size)
{