From 15578f3eb78ffac80ce6d7e8e2cd422e3457f018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 23 Sep 2017 16:26:56 -0700 Subject: [PATCH] Cleanup. --- include/bx/hash.h | 29 +++++++++++---------- include/bx/inline/hash.inl | 53 ++++++++++++++++++++------------------ tests/handle_test.cpp | 10 +++---- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/include/bx/hash.h b/include/bx/hash.h index 6af79c6..1dcd82e 100644 --- a/include/bx/hash.h +++ b/include/bx/hash.h @@ -49,19 +49,6 @@ namespace bx uint32_t m_size; }; - /// - uint32_t hashMurmur2A(const void* _data, uint32_t _size); - - /// - template - 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 + uint32_t hash(const void* _data, uint32_t _size); + + /// + template + uint32_t hash(const Ty& _data); + + /// + template + uint32_t hash(const StringView& _data); + + /// + template + uint32_t hash(const char* _data); + } // namespace bx #include "inline/hash.inl" diff --git a/include/bx/inline/hash.inl b/include/bx/inline/hash.inl index 9ea1296..41031bb 100644 --- a/include/bx/inline/hash.inl +++ b/include/bx/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 - 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 + inline uint32_t hash(const void* _data, uint32_t _size) + { + HashT hh; + hh.begin(); + hh.add(_data, (int)_size); + return hh.end(); + } + + template + inline uint32_t hash(const Ty& _data) + { + BX_STATIC_ASSERT(BX_TYPE_IS_POD(Ty) ); + return hash(&_data, sizeof(Ty) ); + } + + template + inline uint32_t hash(const StringView& _data) + { + return hash(_data.getPtr(), _data.getLength() ); + } + + template + inline uint32_t hash(const char* _data) + { + return hash(StringView(_data) ); + } + } // namespace bx diff --git a/tests/handle_test.cpp b/tests/handle_test.cpp index b82e1da..0539292 100644 --- a/tests/handle_test.cpp +++ b/tests/handle_test.cpp @@ -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(sv0), 0); REQUIRE(ok); - ok = hm.insert(bx::hashMurmur2A(sv0), 0); + ok = hm.insert(bx::hash(sv0), 0); REQUIRE(!ok); REQUIRE(1 == hm.getNumElements() ); bx::StringView sv1("test1"); - ok = hm.insert(bx::hashMurmur2A(sv1), 0); + ok = hm.insert(bx::hash(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(sv0), 0); REQUIRE(ok); - hm.removeByKey(bx::hashMurmur2A(sv0) ); + hm.removeByKey(bx::hash(sv0) ); REQUIRE(0 == hm.getNumElements() ); for (uint32_t ii = 0, num = hm.getMaxCapacity(); ii < num; ++ii)