Use uint32/64/_t instead of Hash32/64_t
This commit is contained in:
@@ -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 = <get next 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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Hash::Function::Fnv1a> () );
|
||||
* 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user