mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Cleanup.
This commit is contained in:
@@ -49,19 +49,6 @@ namespace bx
|
||||
uint32_t m_size;
|
||||
};
|
||||
|
||||
///
|
||||
uint32_t hashMurmur2A(const void* _data, uint32_t _size);
|
||||
|
||||
///
|
||||
template <typename Ty>
|
||||
uint32_t hashMurmur2A(const Ty& _data);
|
||||
|
||||
///
|
||||
uint32_t hashMurmur2A(const StringView& _data);
|
||||
|
||||
///
|
||||
uint32_t hashMurmur2A(const char* _data);
|
||||
|
||||
///
|
||||
class HashAdler32
|
||||
{
|
||||
@@ -115,6 +102,22 @@ namespace bx
|
||||
uint32_t m_hash;
|
||||
};
|
||||
|
||||
///
|
||||
template<typename HashT>
|
||||
uint32_t hash(const void* _data, uint32_t _size);
|
||||
|
||||
///
|
||||
template<typename HashT, typename Ty>
|
||||
uint32_t hash(const Ty& _data);
|
||||
|
||||
///
|
||||
template<typename HashT>
|
||||
uint32_t hash(const StringView& _data);
|
||||
|
||||
///
|
||||
template<typename HashT>
|
||||
uint32_t hash(const char* _data);
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#include "inline/hash.inl"
|
||||
|
||||
@@ -136,31 +136,6 @@ namespace bx
|
||||
#undef MURMUR_R
|
||||
#undef mmix
|
||||
|
||||
inline uint32_t hashMurmur2A(const void* _data, uint32_t _size)
|
||||
{
|
||||
HashMurmur2A murmur;
|
||||
murmur.begin();
|
||||
murmur.add(_data, (int)_size);
|
||||
return murmur.end();
|
||||
}
|
||||
|
||||
template <typename Ty>
|
||||
inline uint32_t hashMurmur2A(const Ty& _data)
|
||||
{
|
||||
BX_STATIC_ASSERT(BX_TYPE_IS_POD(Ty) );
|
||||
return hashMurmur2A(&_data, sizeof(Ty) );
|
||||
}
|
||||
|
||||
inline uint32_t hashMurmur2A(const StringView& _data)
|
||||
{
|
||||
return hashMurmur2A(_data.getPtr(), _data.getLength() );
|
||||
}
|
||||
|
||||
inline uint32_t hashMurmur2A(const char* _data)
|
||||
{
|
||||
return hashMurmur2A(StringView(_data) );
|
||||
}
|
||||
|
||||
inline void HashAdler32::begin()
|
||||
{
|
||||
m_a = 1;
|
||||
@@ -201,4 +176,32 @@ namespace bx
|
||||
return m_hash;
|
||||
}
|
||||
|
||||
template<typename HashT>
|
||||
inline uint32_t hash(const void* _data, uint32_t _size)
|
||||
{
|
||||
HashT hh;
|
||||
hh.begin();
|
||||
hh.add(_data, (int)_size);
|
||||
return hh.end();
|
||||
}
|
||||
|
||||
template<typename HashT, typename Ty>
|
||||
inline uint32_t hash(const Ty& _data)
|
||||
{
|
||||
BX_STATIC_ASSERT(BX_TYPE_IS_POD(Ty) );
|
||||
return hash<HashT>(&_data, sizeof(Ty) );
|
||||
}
|
||||
|
||||
template<typename HashT>
|
||||
inline uint32_t hash(const StringView& _data)
|
||||
{
|
||||
return hash<HashT>(_data.getPtr(), _data.getLength() );
|
||||
}
|
||||
|
||||
template<typename HashT>
|
||||
inline uint32_t hash(const char* _data)
|
||||
{
|
||||
return hash<HashT>(StringView(_data) );
|
||||
}
|
||||
|
||||
} // namespace bx
|
||||
|
||||
@@ -89,26 +89,26 @@ TEST_CASE("HandleHashTable", "")
|
||||
|
||||
bx::StringView sv0("test0");
|
||||
|
||||
bool ok = hm.insert(bx::hashMurmur2A(sv0), 0);
|
||||
bool ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv0), 0);
|
||||
REQUIRE(ok);
|
||||
|
||||
ok = hm.insert(bx::hashMurmur2A(sv0), 0);
|
||||
ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv0), 0);
|
||||
REQUIRE(!ok);
|
||||
REQUIRE(1 == hm.getNumElements() );
|
||||
|
||||
bx::StringView sv1("test1");
|
||||
|
||||
ok = hm.insert(bx::hashMurmur2A(sv1), 0);
|
||||
ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv1), 0);
|
||||
REQUIRE(ok);
|
||||
REQUIRE(2 == hm.getNumElements() );
|
||||
|
||||
hm.removeByHandle(0);
|
||||
REQUIRE(0 == hm.getNumElements() );
|
||||
|
||||
ok = hm.insert(bx::hashMurmur2A(sv0), 0);
|
||||
ok = hm.insert(bx::hash<bx::HashMurmur2A>(sv0), 0);
|
||||
REQUIRE(ok);
|
||||
|
||||
hm.removeByKey(bx::hashMurmur2A(sv0) );
|
||||
hm.removeByKey(bx::hash<bx::HashMurmur2A>(sv0) );
|
||||
REQUIRE(0 == hm.getNumElements() );
|
||||
|
||||
for (uint32_t ii = 0, num = hm.getMaxCapacity(); ii < num; ++ii)
|
||||
|
||||
Reference in New Issue
Block a user