mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added MurmurHash3.
This commit is contained in:
@@ -76,7 +76,7 @@ namespace bx
|
||||
uint32_t m_hash;
|
||||
};
|
||||
|
||||
/// 32-bit multiply and rotate hash.
|
||||
/// 32-bit non-cryptographic multiply and rotate hash.
|
||||
class HashMurmur2A
|
||||
{
|
||||
public:
|
||||
@@ -101,9 +101,39 @@ namespace bx
|
||||
|
||||
private:
|
||||
uint32_t m_hash;
|
||||
uint32_t m_tail;
|
||||
uint32_t m_count;
|
||||
uint32_t m_size;
|
||||
uint8_t m_tail[4];
|
||||
uint8_t m_count;
|
||||
};
|
||||
|
||||
/// 32-bit non-cryptographic multiply and rotate hash.
|
||||
class HashMurmur3
|
||||
{
|
||||
public:
|
||||
///
|
||||
void begin(uint32_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);
|
||||
|
||||
///
|
||||
uint32_t end();
|
||||
|
||||
private:
|
||||
uint32_t m_hash;
|
||||
uint32_t m_size;
|
||||
uint8_t m_tail[4];
|
||||
uint8_t m_count;
|
||||
};
|
||||
|
||||
///
|
||||
|
||||
@@ -73,9 +73,8 @@ namespace bx
|
||||
inline void HashMurmur2A::begin(uint32_t _seed)
|
||||
{
|
||||
m_hash = _seed;
|
||||
m_tail = 0;
|
||||
m_count = 0;
|
||||
m_size = 0;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
inline void HashMurmur2A::add(const char* _data)
|
||||
@@ -94,6 +93,29 @@ namespace bx
|
||||
add(&_data, sizeof(Ty) );
|
||||
}
|
||||
|
||||
inline void HashMurmur3::begin(uint32_t _seed)
|
||||
{
|
||||
m_hash = _seed;
|
||||
m_size = 0;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
inline void HashMurmur3::add(const char* _data)
|
||||
{
|
||||
return add(StringView(_data) );
|
||||
}
|
||||
|
||||
inline void HashMurmur3::add(const StringView& _data)
|
||||
{
|
||||
return add(_data.getPtr(), _data.getLength() );
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline void HashMurmur3::add(const Ty& _data)
|
||||
{
|
||||
add(&_data, sizeof(Ty) );
|
||||
}
|
||||
|
||||
template<typename HashT>
|
||||
inline uint32_t hash(const void* _data, uint32_t _size)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user