From efe21f7763ae5d4571ac48036d23677eab4253bb Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Tue, 13 Nov 2012 16:41:46 -0800 Subject: [PATCH] Use uint32/64/_t instead of Hash32/64_t --- doc/manual/source/hash-functions.rst | 16 +++++-------- src/core/model/hash-fnv.cc | 4 ++-- src/core/model/hash-fnv.h | 4 ++-- src/core/model/hash-function.cc | 2 +- src/core/model/hash-function.h | 22 ++++++++--------- src/core/model/hash-murmur3.cc | 8 +++---- src/core/model/hash-murmur3.h | 6 ++--- src/core/model/hash.h | 36 ++++++++++++++-------------- src/core/test/hash-test-suite.cc | 30 +++++++++++------------ 9 files changed, 62 insertions(+), 66 deletions(-) diff --git a/doc/manual/source/hash-functions.rst b/doc/manual/source/hash-functions.rst index ce5fcf943..64569c634 100644 --- a/doc/manual/source/hash-functions.rst +++ b/doc/manual/source/hash-functions.rst @@ -27,16 +27,12 @@ The simplest way to get a hash value of a data buffer or string is just:: char * buffer = ... size_t buffer_size = ... - Hash32_t buffer_hash = Hash32 ( buffer, buffer_size); + uint32_t buffer_hash = Hash32 ( buffer, buffer_size); std::string s; - Hash32_t string_hash = Hash32 (s); + uint32_t string_hash = Hash32 (s); -The ``Hash32_t`` type (just an ``uint32_t``) is a reminder that -hash values are opaque. - -Equivalent functions and ``Hash64_t`` type are defined for 64-bit hash -values. +Equivalent functions are defined for 64-bit hash values. Incremental Hashing ******************* @@ -62,7 +58,7 @@ This is almost as straight-forward as the first example: buffer = ; hasher (buffer, buffer_size); } - Hash32_t combined_hash = hasher.GetHash32 (); + uint32_t combined_hash = hasher.GetHash32 (); By default ``Hasher`` preserves internal state to enable incremental hashing. If you want to reuse a ``Hasher`` object (for example @@ -106,8 +102,8 @@ even need to create a new class derived from HashImplementation:: For this to compile, your ``hashf`` has to match one of the function pointer signatures:: - typedef Hash::Hash32_t (*Hash32Function_ptr) (const char *, const size_t); - typedef Hash::Hash64_t (*Hash64Function_ptr) (const char *, const size_t); + typedef uint32_t (*Hash32Function_ptr) (const char *, const size_t); + typedef uint64_t (*Hash64Function_ptr) (const char *, const size_t); Sources for Hash Functions diff --git a/src/core/model/hash-fnv.cc b/src/core/model/hash-fnv.cc index abf667d4b..cffe60800 100644 --- a/src/core/model/hash-fnv.cc +++ b/src/core/model/hash-fnv.cc @@ -734,7 +734,7 @@ Fnv1a::Fnv1a () clear (); } -Hash32_t +uint32_t Fnv1a::GetHash32 (const char * buffer, const size_t size) { m_hash32 = @@ -742,7 +742,7 @@ Fnv1a::GetHash32 (const char * buffer, const size_t size) return m_hash32; } -Hash64_t +uint64_t Fnv1a::GetHash64 (const char * buffer, const size_t size) { m_hash64 = diff --git a/src/core/model/hash-fnv.h b/src/core/model/hash-fnv.h index d4c4d75e0..0ab99455a 100644 --- a/src/core/model/hash-fnv.h +++ b/src/core/model/hash-fnv.h @@ -65,7 +65,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 32-bit hash of the buffer */ - Hash32_t GetHash32 (const char * buffer, const size_t size); + uint32_t GetHash32 (const char * buffer, const size_t size); /** * Compute 64-bit hash of a byte buffer. * @@ -80,7 +80,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 64-bit hash of the buffer */ - Hash64_t GetHash64 (const char * buffer, const size_t size); + uint64_t GetHash64 (const char * buffer, const size_t size); /** * Restore initial state */ diff --git a/src/core/model/hash-function.cc b/src/core/model/hash-function.cc index 28795e46b..37a331c3f 100644 --- a/src/core/model/hash-function.cc +++ b/src/core/model/hash-function.cc @@ -28,7 +28,7 @@ NS_LOG_COMPONENT_DEFINE ("HashFunction"); namespace Hash { -Hash64_t +uint64_t Implementation::GetHash64 (const char * buffer, const size_t size) { NS_LOG_WARN ("64-bit hash requested, only 32-bit implementation available"); diff --git a/src/core/model/hash-function.h b/src/core/model/hash-function.h index a56b512f6..a900c421f 100644 --- a/src/core/model/hash-function.h +++ b/src/core/model/hash-function.h @@ -30,8 +30,8 @@ namespace ns3 { * * Hash value opaque types */ -typedef uint32_t Hash32_t; -typedef uint64_t Hash64_t; +typedef uint32_t uint32_t; +typedef uint64_t uint64_t; namespace Hash { @@ -57,7 +57,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 32-bit hash of the buffer */ - virtual Hash32_t GetHash32 (const char * buffer, const size_t size) = 0; + virtual uint32_t GetHash32 (const char * buffer, const size_t size) = 0; /** * Compute 64-bit hash of a byte buffer. * @@ -74,7 +74,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 64-bit hash of the buffer */ - virtual Hash64_t GetHash64 (const char * buffer, const size_t size); + virtual uint64_t GetHash64 (const char * buffer, const size_t size); /** * Restore initial state */ @@ -103,8 +103,8 @@ public: * * See Hash32Implementation<> or Hash64Implementation<> */ -typedef Hash32_t (*Hash32Function_ptr) (const char *, const size_t); -typedef Hash64_t (*Hash64Function_ptr) (const char *, const size_t); +typedef uint32_t (*Hash32Function_ptr) (const char *, const size_t); +typedef uint64_t (*Hash64Function_ptr) (const char *, const size_t); namespace Function { @@ -117,7 +117,7 @@ class Hash32 : public Implementation { public: Hash32 (Hash32Function_ptr hp) : m_fp (hp) { }; - Hash32_t GetHash32 (const char * buffer, const size_t size) + uint32_t GetHash32 (const char * buffer, const size_t size) { return (*m_fp) (buffer, size); } @@ -135,14 +135,14 @@ class Hash64 : public Implementation { public: Hash64 (Hash64Function_ptr hp) : m_fp (hp) { }; - Hash64_t GetHash64 (const char * buffer, const size_t size) + uint64_t GetHash64 (const char * buffer, const size_t size) { return (*m_fp) (buffer, size); } - Hash32_t GetHash32 (const char * buffer, const size_t size) + uint32_t GetHash32 (const char * buffer, const size_t size) { - Hash64_t hash = GetHash64 (buffer, size); - return *(Hash32_t *)(void *)(&hash); + uint64_t hash = GetHash64 (buffer, size); + return *(uint32_t *)(void *)(&hash); } void clear () { }; private: diff --git a/src/core/model/hash-murmur3.cc b/src/core/model/hash-murmur3.cc index 6bf8185f5..02bb64ae6 100644 --- a/src/core/model/hash-murmur3.cc +++ b/src/core/model/hash-murmur3.cc @@ -430,27 +430,27 @@ Murmur3:: Murmur3 () clear (); } -Hash32_t +uint32_t Murmur3::GetHash32 (const char * buffer, const size_t size) { using namespace Murmur3Implementation; MurmurHash3_x86_32_incr (buffer, size, m_hash32, (void *) & m_hash32); m_size32 += size; - Hash32_t hash; + uint32_t hash; MurmurHash3_x86_32_fin (m_size32, m_hash32, (void *) & hash); return hash; } -Hash64_t +uint64_t Murmur3::GetHash64 (const char * buffer, const size_t size) { using namespace Murmur3Implementation; MurmurHash3_x86_128_incr (buffer, size, (uint32_t *)(void *)m_hash64, (void *)(m_hash64)); m_size64 += size; - Hash64_t hash[2]; + uint64_t hash[2]; MurmurHash3_x86_128_fin (m_size64, (uint32_t*)(void *)m_hash64, (void *)hash); return hash[0]; diff --git a/src/core/model/hash-murmur3.h b/src/core/model/hash-murmur3.h index 16b04c142..d4d75dcda 100644 --- a/src/core/model/hash-murmur3.h +++ b/src/core/model/hash-murmur3.h @@ -65,7 +65,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 32-bit hash of the buffer */ - Hash32_t GetHash32 (const char * buffer, const size_t size); + uint32_t GetHash32 (const char * buffer, const size_t size); /** * Compute 64-bit hash of a byte buffer. * @@ -80,7 +80,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 64-bit hash of the buffer */ - Hash64_t GetHash64 (const char * buffer, const size_t size); + uint64_t GetHash64 (const char * buffer, const size_t size); /** * Restore initial state */ @@ -97,7 +97,7 @@ private: { SEED = 0x8BADF00D // Ate bad food }; - /@{ + //@{ /** * Cache last hash value, and total bytes hashed, * for incremental hashing diff --git a/src/core/model/hash.h b/src/core/model/hash.h index 4ff9a82b4..4a643625d 100644 --- a/src/core/model/hash.h +++ b/src/core/model/hash.h @@ -26,7 +26,7 @@ #include "assert.h" #include "ptr.h" -#include "hash-function.h" // typedef ns3::Hash32_t, ns3::Hash64_t +#include "hash-function.h" // typedef ns3::uint32_t, ns3::uint64_t #include "hash-murmur3.h" #include "hash-fnv.h" @@ -50,7 +50,7 @@ namespace ns3 { * The choice of hash function can be made at construction by * \code * Hasher hasher = Hasher ( Create () ); - * Hash32_t hash = Hasher.GetHash32 (data); + * uint32_t hash = Hasher.GetHash32 (data); * \endcode * * The available implementations are documented in group hash. @@ -96,7 +96,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 32-bit hash of the buffer */ - Hash32_t GetHash32 (const char * buffer, const size_t size); + uint32_t GetHash32 (const char * buffer, const size_t size); /** * Compute 64-bit hash of a byte buffer * @@ -111,7 +111,7 @@ public: * \param [in] size length of the buffer, in bytes * \return 64-bit hash of the buffer */ - Hash64_t GetHash64 (const char * buffer, const size_t size); + uint64_t GetHash64 (const char * buffer, const size_t size); /** * Compute 32-bit hash of a string @@ -126,7 +126,7 @@ public: * \param [in] s string to hash * \return 32-bit hash of the string */ - Hash32_t GetHash32 (const std::string s); + uint32_t GetHash32 (const std::string s); /** * Compute 64-bit hash of a string * @@ -140,7 +140,7 @@ public: * \param [in] s string to hash * \return 64-bit hash of the string */ - Hash64_t GetHash64 (const std::string s); + uint64_t GetHash64 (const std::string s); /** * Restore initial state * @@ -166,7 +166,7 @@ private: * \param [in] size length of the buffer, in bytes * \return 32-bit hash of the buffer */ -Hash32_t Hash32 (const char * buffer, const size_t size); +uint32_t Hash32 (const char * buffer, const size_t size); /** * \ingroup hash * @@ -176,7 +176,7 @@ Hash32_t Hash32 (const char * buffer, const size_t size); * \param [in] size length of the buffer, in bytes * \return 64-bit hash of the buffer */ -Hash64_t Hash64 (const char * buffer, const size_t size); +uint64_t Hash64 (const char * buffer, const size_t size); /** * \ingroup hash @@ -186,7 +186,7 @@ Hash64_t Hash64 (const char * buffer, const size_t size); * \param [in] s string to hash * \return 32-bit hash of the string */ -Hash32_t Hash32 (const std::string s); +uint32_t Hash32 (const std::string s); /** * \ingroup hash * @@ -195,7 +195,7 @@ Hash32_t Hash32 (const std::string s); * \param [in] s string to hash * \return 64-bit hash of the string */ -Hash64_t Hash64 (const std::string s); +uint64_t Hash64 (const std::string s); } // namespace ns3 @@ -211,7 +211,7 @@ namespace ns3 { */ inline -Hash32_t +uint32_t Hasher::GetHash32 (const char * buffer, const size_t size) { NS_ASSERT (m_impl != 0); @@ -219,7 +219,7 @@ Hasher::GetHash32 (const char * buffer, const size_t size) } inline -Hash64_t +uint64_t Hasher::GetHash64 (const char * buffer, const size_t size) { NS_ASSERT (m_impl != 0); @@ -227,7 +227,7 @@ Hasher::GetHash64 (const char * buffer, const size_t size) } inline -Hash32_t +uint32_t Hasher::GetHash32 (const std::string s) { NS_ASSERT (m_impl != 0); @@ -235,7 +235,7 @@ Hasher::GetHash32 (const std::string s) } inline -Hash64_t +uint64_t Hasher::GetHash64 (const std::string s) { NS_ASSERT (m_impl != 0); @@ -248,28 +248,28 @@ Hasher::GetHash64 (const std::string s) */ inline -Hash32_t +uint32_t Hash32 (const char * buffer, const size_t size) { return Hasher ().GetHash32 (buffer, size); } inline -Hash64_t +uint64_t Hash64 (const char * buffer, const size_t size) { return Hasher ().GetHash64 (buffer, size); } inline -Hash32_t +uint32_t Hash32 (const std::string s) { return Hasher ().GetHash32 (s); } inline -Hash64_t +uint64_t Hash64 (const std::string s) { return Hasher ().GetHash64 (s); diff --git a/src/core/test/hash-test-suite.cc b/src/core/test/hash-test-suite.cc index 167c8a341..f7b63a71a 100644 --- a/src/core/test/hash-test-suite.cc +++ b/src/core/test/hash-test-suite.cc @@ -32,13 +32,13 @@ public: HashTestCase (const std::string name); virtual ~HashTestCase (); protected: - void Check ( const std::string hashName, const Hash32_t hash); - void Check ( const std::string hashName, const Hash64_t hash); + void Check ( const std::string hashName, const uint32_t hash); + void Check ( const std::string hashName, const uint64_t hash); std::string key; - Hash32_t hash32Reference; - Hash64_t hash64Reference; + uint32_t hash32Reference; + uint64_t hash64Reference; private: - void Check ( const std::string hashName, const int bits, const Hash64_t hash); + void Check ( const std::string hashName, const int bits, const uint64_t hash); virtual void DoRun (void); }; // class HashTestCase @@ -53,23 +53,23 @@ HashTestCase::~HashTestCase () } void -HashTestCase::Check ( const std::string hashName, const Hash32_t hash) +HashTestCase::Check ( const std::string hashName, const uint32_t hash) { Check (hashName, 32, hash); } void -HashTestCase::Check ( const std::string hashName, const Hash64_t hash) +HashTestCase::Check ( const std::string hashName, const uint64_t hash) { Check (hashName, 64, hash); } void -HashTestCase::Check ( std::string hashName, int bits, Hash64_t hash) +HashTestCase::Check ( std::string hashName, int bits, uint64_t hash) { int w; std::string type; - Hash64_t hashRef; + uint64_t hashRef; if (bits == 32) { @@ -231,19 +231,19 @@ gnu_sum (const char * buffer, const size_t size) } // Hash32FunctionPtr -Hash32_t +uint32_t gnu_sum32 (const char * buffer, const size_t size) { - Hash32_t h = gnu_sum (buffer, size); - return (Hash32_t)( (h << 16) + h); + uint32_t h = gnu_sum (buffer, size); + return (uint32_t)( (h << 16) + h); } // Hash64FunctionPtr -Hash64_t +uint64_t gnu_sum64 (const char * buffer, const size_t size) { - Hash64_t h = gnu_sum32 (buffer, size); - return (Hash64_t)( (h << 32) + h); + uint64_t h = gnu_sum32 (buffer, size); + return (uint64_t)( (h << 32) + h); } class Hash32FunctionPtrTestCase : public HashTestCase