Refactor namespaces
This commit is contained in:
@@ -38,9 +38,11 @@ namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Hash-Fnv");
|
||||
|
||||
namespace HashFunction {
|
||||
namespace Hash {
|
||||
|
||||
namespace Fnv1aImplementation {
|
||||
namespace Function {
|
||||
|
||||
namespace Fnv1aImplementation {
|
||||
|
||||
/*************************************************
|
||||
** class FnvHashImplementation
|
||||
@@ -151,7 +153,7 @@ typedef u_int32_t Fnv32_t;
|
||||
*
|
||||
* Use fully qualified type so this define works outside this scope //PDB
|
||||
*/
|
||||
#define FNV0_32_INIT ((HashFunction::Fnv1aImplementation::Fnv32_t)0)
|
||||
#define FNV0_32_INIT ((Fnv1aImplementation::Fnv32_t)0)
|
||||
|
||||
|
||||
/*
|
||||
@@ -168,7 +170,7 @@ typedef u_int32_t Fnv32_t;
|
||||
*
|
||||
* Use fully qualified type so this define works outside this scope //PDB
|
||||
*/
|
||||
#define FNV1_32_INIT ((HashFunction::Fnv1aImplementation::Fnv32_t)0x811c9dc5)
|
||||
#define FNV1_32_INIT ((Fnv1aImplementation::Fnv32_t)0x811c9dc5)
|
||||
#define FNV1_32A_INIT FNV1_32_INIT
|
||||
|
||||
|
||||
@@ -201,10 +203,10 @@ typedef struct {
|
||||
* Use fully qualified type so this define works outside this scope //PDB
|
||||
*/
|
||||
#if defined(HAVE_64BIT_LONG_LONG)
|
||||
#define FNV0_64_INIT ((HashFunction::Fnv1aImplementation::Fnv64_t)0)
|
||||
#define FNV0_64_INIT ((Fnv1aImplementation::Fnv64_t)0)
|
||||
#else /* HAVE_64BIT_LONG_LONG */
|
||||
extern const Fnv64_t fnv0_64_init;
|
||||
#define FNV0_64_INIT (HashFunction::Fnv1aImplementation::fnv0_64_init)
|
||||
#define FNV0_64_INIT (Fnv1aImplementation::fnv0_64_init)
|
||||
#endif /* HAVE_64BIT_LONG_LONG */
|
||||
|
||||
|
||||
@@ -221,7 +223,7 @@ extern const Fnv64_t fnv0_64_init;
|
||||
* NOTE: The FNV-1a initial basis is the same value as FNV-1 by definition.
|
||||
*/
|
||||
#if defined(HAVE_64BIT_LONG_LONG)
|
||||
#define FNV1_64_INIT ((HashFunction::Fnv1aImplementation::Fnv64_t)0xcbf29ce484222325ULL)
|
||||
#define FNV1_64_INIT ((Fnv1aImplementation::Fnv64_t)0xcbf29ce484222325ULL)
|
||||
#define FNV1A_64_INIT FNV1_64_INIT
|
||||
#else /* HAVE_64BIT_LONG_LONG */
|
||||
extern const fnv1_64_init;
|
||||
@@ -337,7 +339,7 @@ enum fnv_type {
|
||||
/*
|
||||
* 32 bit magic FNV-1a prime
|
||||
*/
|
||||
#define FNV_32_PRIME ((HashFunction::Fnv1aImplementation::Fnv32_t)0x01000193)
|
||||
#define FNV_32_PRIME ((Fnv1aImplementation::Fnv32_t)0x01000193)
|
||||
|
||||
|
||||
/*
|
||||
@@ -496,7 +498,7 @@ const Fnv64_t fnv1a_64_init = { 0x84222325, 0xcbf29ce4 };
|
||||
* 64 bit magic FNV-1a prime
|
||||
*/
|
||||
#if defined(HAVE_64BIT_LONG_LONG)
|
||||
#define FNV_64_PRIME ((HashFunction::Fnv1aImplementation::Fnv64_t)0x100000001b3ULL)
|
||||
#define FNV_64_PRIME ((Fnv1aImplementation::Fnv64_t)0x100000001b3ULL)
|
||||
#else /* HAVE_64BIT_LONG_LONG */
|
||||
#define FNV_64_PRIME_LOW ((unsigned long)0x1b3) /* lower bits of FNV prime */
|
||||
#define FNV_64_PRIME_SHIFT (8) /* top FNV prime shift above 2^32 */
|
||||
@@ -722,7 +724,7 @@ fnv_64a_str(char *str, Fnv64_t hval)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // namespace Fnv1aImplementation
|
||||
} // namespace Fnv1aImplementation
|
||||
|
||||
|
||||
|
||||
@@ -747,6 +749,8 @@ Fnv1a::clear (void)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace HashFunction
|
||||
} // namespace Function
|
||||
|
||||
} // namespace Hash
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -21,11 +21,13 @@
|
||||
#ifndef HASH_FNV_H
|
||||
#define HASH_FNV_H
|
||||
|
||||
#include "hash-implementation.h"
|
||||
#include "hash-function.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
namespace HashFunction {
|
||||
namespace Hash {
|
||||
|
||||
namespace Function {
|
||||
|
||||
/**
|
||||
* \ingroup hash
|
||||
@@ -33,7 +35,7 @@ namespace ns3 {
|
||||
* \brief Fnv1a hash function implementation
|
||||
*
|
||||
*/
|
||||
class Fnv1a : public HashImplementation
|
||||
class Fnv1a : public Implementation
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -68,7 +70,9 @@ private:
|
||||
|
||||
}; // class Fnv1a
|
||||
|
||||
} // namespace HashFunction
|
||||
} // namespace Function
|
||||
|
||||
} // namespace Hash
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
@@ -19,23 +19,22 @@
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "hash-implementation.h"
|
||||
#include "hash-function.h"
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("HashImplementation");
|
||||
NS_LOG_COMPONENT_DEFINE ("HashFunction");
|
||||
|
||||
|
||||
/*************************************************
|
||||
** class HashImplementation
|
||||
************************************************/
|
||||
namespace Hash {
|
||||
|
||||
Hash64_t
|
||||
HashImplementation::GetHash64 (const char * buffer, const size_t size)
|
||||
Implementation::GetHash64 (const char * buffer, const size_t size)
|
||||
{
|
||||
NS_LOG_WARN("64-bit hash requested, only 32-bit implementation available");
|
||||
return GetHash32 (buffer, size);
|
||||
}
|
||||
|
||||
} // namespace Hash
|
||||
|
||||
} // namespace ns3
|
||||
@@ -18,8 +18,8 @@
|
||||
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
|
||||
*/
|
||||
|
||||
#ifndef HASHIMPLEMENTATION_H
|
||||
#define HASHIMPLEMENTATION_H
|
||||
#ifndef HASHFUNCTION_H
|
||||
#define HASHFUNCTION_H
|
||||
|
||||
#include "simple-ref-count.h"
|
||||
|
||||
@@ -33,13 +33,14 @@ namespace ns3 {
|
||||
typedef uint32_t Hash32_t;
|
||||
typedef uint64_t Hash64_t;
|
||||
|
||||
|
||||
namespace Hash {
|
||||
|
||||
/**
|
||||
* \ingroup hash
|
||||
*
|
||||
* \brief Hash function implementation base class
|
||||
*/
|
||||
class HashImplementation : public SimpleRefCount<HashImplementation>
|
||||
class Implementation : public SimpleRefCount<Implementation>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -64,11 +65,15 @@ public:
|
||||
* Restore initial state
|
||||
*/
|
||||
virtual void clear (void) = 0;
|
||||
/*
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Implementation () {} ;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~HashImplementation () {} ;
|
||||
}; // HashImplementation
|
||||
virtual ~Implementation () {} ;
|
||||
}; // Hashfunction
|
||||
|
||||
|
||||
/*--------------------------------------
|
||||
@@ -87,28 +92,29 @@ public:
|
||||
typedef Hash32_t (*Hash32Function_ptr) (const char *, const size_t);
|
||||
typedef Hash64_t (*Hash64Function_ptr) (const char *, const size_t);
|
||||
|
||||
namespace Function {
|
||||
|
||||
/**
|
||||
* \ingroup hash
|
||||
*
|
||||
* \brief Template for HashImplementations from 32-bit hash functions
|
||||
* \brief Template for Hashfunctions from 32-bit hash functions
|
||||
*/
|
||||
template <Hash32Function_ptr hp>
|
||||
class Hash32Implementation : public HashImplementation
|
||||
class Hash32 : public Implementation
|
||||
{
|
||||
Hash32_t GetHash32 (const char * buffer, const size_t size)
|
||||
{
|
||||
return (*hp) (buffer, size);
|
||||
}
|
||||
}; // Hash32Implementation<HashFunction>
|
||||
}; // Hash32<Hash32Function_ptr>
|
||||
|
||||
/**
|
||||
* \ingroup hash
|
||||
*
|
||||
* \brief Template for HashImplementations from 64-bit hash functions
|
||||
* \brief Template for Hashfunctions from 64-bit hash functions
|
||||
*/
|
||||
template <Hash64Function_ptr hp>
|
||||
class Hash64Implementation : public HashImplementation
|
||||
class Hash64 : public Implementation
|
||||
{
|
||||
Hash64_t GetHash64 (const char * buffer, const size_t size)
|
||||
{
|
||||
@@ -119,9 +125,14 @@ class Hash64Implementation : public HashImplementation
|
||||
Hash64_t hash = GetHash64(buffer, size);
|
||||
return (Hash32_t *)(&hash);
|
||||
}
|
||||
}; // Hash32Implementation<HashFunction>
|
||||
}; // Hash64<Hash64Function_ptr>
|
||||
|
||||
|
||||
} // namespace Function
|
||||
|
||||
} // namespace Hash
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* HASHIMPLEMENTATION_H */
|
||||
#endif /* HASHFUNCTION_H */
|
||||
|
||||
@@ -25,9 +25,11 @@ namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Hash-Murmur3");
|
||||
|
||||
namespace HashFunction {
|
||||
namespace Hash {
|
||||
|
||||
namespace Murmur3Implementation {
|
||||
namespace Function {
|
||||
|
||||
namespace Murmur3Implementation {
|
||||
|
||||
/*************************************************
|
||||
** class Murmur3HashImplementation
|
||||
@@ -351,10 +353,9 @@ void MurmurHash3_x64_128 ( const void * key, const int len,
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // namespace Murmur3Implementation
|
||||
|
||||
|
||||
} // namespace Murmur3Implementation
|
||||
|
||||
|
||||
Hash32_t
|
||||
Murmur3::GetHash32 (const char * buffer, const size_t size)
|
||||
{
|
||||
@@ -379,6 +380,8 @@ Murmur3::clear (void)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace HashFunction
|
||||
} // namespace Function
|
||||
|
||||
} // namespace Hash
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
@@ -21,11 +21,13 @@
|
||||
#ifndef HASH_MURMUR3_H
|
||||
#define HASH_MURMUR3_H
|
||||
|
||||
#include "hash-implementation.h"
|
||||
#include "hash-function.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
namespace HashFunction {
|
||||
namespace Hash {
|
||||
|
||||
namespace Function {
|
||||
|
||||
/**
|
||||
* \ingroup hash
|
||||
@@ -42,7 +44,7 @@ namespace ns3 {
|
||||
* compile and run any of them on any platform, but your performance with the
|
||||
* non-native version will be less than optimal.
|
||||
*/
|
||||
class Murmur3 : public HashImplementation
|
||||
class Murmur3 : public Implementation
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -80,7 +82,9 @@ private:
|
||||
|
||||
}; // class Murmur3
|
||||
|
||||
} // namespace HashFunction
|
||||
} // namespace Function
|
||||
|
||||
} // namespace Hash
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
@@ -26,24 +26,20 @@ namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Hash");
|
||||
|
||||
/*************************************************
|
||||
** class Hash
|
||||
************************************************/
|
||||
|
||||
Hash::Hash ()
|
||||
Hasher::Hasher ()
|
||||
{
|
||||
m_impl = Create <HashFunction::Murmur3> ();
|
||||
m_impl = Create <Hash::Function::Murmur3> ();
|
||||
NS_ASSERT (m_impl != 0);
|
||||
}
|
||||
|
||||
Hash::Hash (Ptr<HashImplementation> hp)
|
||||
Hasher::Hasher (Ptr<Hash::Implementation> hp)
|
||||
: m_impl(hp)
|
||||
{
|
||||
NS_ASSERT (m_impl != 0);
|
||||
}
|
||||
|
||||
Hash &
|
||||
Hash::clear (void)
|
||||
Hasher &
|
||||
Hasher::clear (void)
|
||||
{
|
||||
m_impl->clear();
|
||||
return *this;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "assert.h"
|
||||
#include "ptr.h"
|
||||
|
||||
#include "hash-implementation.h" // typedef ns3::Hash32_t, ns3::Hash64_t
|
||||
#include "hash-function.h" // typedef ns3::Hash32_t, ns3::Hash64_t
|
||||
#include "hash-murmur3.h"
|
||||
#include "hash-fnv.h"
|
||||
|
||||
@@ -40,7 +40,11 @@ namespace ns3 {
|
||||
* This class provides a generic interface for computing hashes
|
||||
* of buffers. Various getters return hashes of different lengths.
|
||||
* The choice of hash function can be made at construction by
|
||||
* passing a Ptr<> to the desired HashImplementation.
|
||||
* \code
|
||||
* Hasher hasher = Hasher ( Create<Hash::Function::Fnv1a> () );
|
||||
* Hash32_t hash = Hasher.GetHash32 (data);
|
||||
* \endcode
|
||||
*
|
||||
* The available implementations are documented in group hash.
|
||||
* The default implementation is Murmur3. FNV1a is also available.
|
||||
*
|
||||
@@ -57,22 +61,19 @@ namespace ns3 {
|
||||
* but our \ref buffer class seems a bit overkill for this case.
|
||||
*
|
||||
*/
|
||||
class Hash
|
||||
class Hasher
|
||||
{
|
||||
public:
|
||||
typedef uint32_t Hash32_t;
|
||||
typedef uint64_t Hash64_t;
|
||||
|
||||
/**
|
||||
* Constructor using the default implementation
|
||||
*/
|
||||
Hash ();
|
||||
Hasher ();
|
||||
/**
|
||||
* Constructor using the supplied implementation
|
||||
*
|
||||
* \param [in] hp Ptr<HashImplementation> to the desired implementation
|
||||
* \param [in] hp Ptr<Hash::Implementation> to the desired implementation
|
||||
*/
|
||||
Hash (Ptr<HashImplementation> hp);
|
||||
Hasher (Ptr<Hash::Implementation> hp);
|
||||
/**
|
||||
* Compute 32-bit hash of a byte buffer
|
||||
*
|
||||
@@ -109,12 +110,12 @@ public:
|
||||
*
|
||||
* \return this
|
||||
*/
|
||||
Hash & clear (void);
|
||||
Hasher & clear (void);
|
||||
|
||||
private:
|
||||
Ptr<HashImplementation> m_impl; /** Hash implementation */
|
||||
Ptr<Hash::Implementation> m_impl; /** Hash implementation */
|
||||
|
||||
}; // Hash
|
||||
}; // Hasher
|
||||
|
||||
|
||||
/*************************************************
|
||||
@@ -176,7 +177,7 @@ namespace ns3 {
|
||||
|
||||
inline
|
||||
Hash32_t
|
||||
Hash::GetHash32 (const char * buffer, const size_t size)
|
||||
Hasher::GetHash32 (const char * buffer, const size_t size)
|
||||
{
|
||||
NS_ASSERT (m_impl != 0);
|
||||
return m_impl->GetHash32 (buffer, size);
|
||||
@@ -184,7 +185,7 @@ Hash::GetHash32 (const char * buffer, const size_t size)
|
||||
|
||||
inline
|
||||
Hash64_t
|
||||
Hash::GetHash64 (const char * buffer, const size_t size)
|
||||
Hasher::GetHash64 (const char * buffer, const size_t size)
|
||||
{
|
||||
NS_ASSERT (m_impl != 0);
|
||||
return m_impl->GetHash64 (buffer, size);
|
||||
@@ -192,7 +193,7 @@ Hash::GetHash64 (const char * buffer, const size_t size)
|
||||
|
||||
inline
|
||||
Hash32_t
|
||||
Hash::GetHash32 (const std::string s)
|
||||
Hasher::GetHash32 (const std::string s)
|
||||
{
|
||||
NS_ASSERT (m_impl != 0);
|
||||
return m_impl->GetHash32 (s.c_str (), s.size ());
|
||||
@@ -200,7 +201,7 @@ Hash::GetHash32 (const std::string s)
|
||||
|
||||
inline
|
||||
Hash64_t
|
||||
Hash::GetHash64 (const std::string s)
|
||||
Hasher::GetHash64 (const std::string s)
|
||||
{
|
||||
NS_ASSERT (m_impl != 0);
|
||||
return m_impl->GetHash64 (s.c_str (), s.size ());
|
||||
@@ -215,28 +216,28 @@ inline
|
||||
Hash32_t
|
||||
Hash32 (const char * buffer, const size_t size)
|
||||
{
|
||||
return Hash().GetHash32 (buffer, size);
|
||||
return Hasher().GetHash32 (buffer, size);
|
||||
}
|
||||
|
||||
inline
|
||||
Hash64_t
|
||||
Hash64 (const char * buffer, const size_t size)
|
||||
{
|
||||
return Hash().GetHash64 (buffer, size);
|
||||
return Hasher().GetHash64 (buffer, size);
|
||||
}
|
||||
|
||||
inline
|
||||
Hash32_t
|
||||
Hash32 (const std::string s)
|
||||
{
|
||||
return Hash().GetHash32 (s);
|
||||
return Hasher().GetHash32 (s);
|
||||
}
|
||||
|
||||
inline
|
||||
Hash64_t
|
||||
Hash64 (const std::string s)
|
||||
{
|
||||
return Hash().GetHash64 (s);
|
||||
return Hasher().GetHash64 (s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ private:
|
||||
};
|
||||
|
||||
HashFnv1aTestCase::HashFnv1aTestCase ()
|
||||
: TestCase ("Check FNV1A Hash on a known string")
|
||||
: TestCase ("Check Fnv1a Hash on a known string")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -95,9 +95,9 @@ void
|
||||
HashFnv1aTestCase::DoRun (void)
|
||||
{
|
||||
std::string key("The quick brown fnv1a.");
|
||||
Hash hasher = Hash ( Create<HashFunction::Fnv1a> () );
|
||||
Hasher hasher = Hasher ( Create<Hash::Function::Fnv1a> () );
|
||||
|
||||
uint32_t h32r = 0x5735855b; // FNV1A(key)
|
||||
uint32_t h32r = 0x5735855b; // Fnv1a(key)
|
||||
uint32_t h32 = hasher.clear ().GetHash32 (key);
|
||||
NS_TEST_ASSERT_MSG_EQ (h32, h32r,
|
||||
"Hash32 produced " << std::hex << std::setw ( 8) << h32
|
||||
@@ -139,7 +139,7 @@ void
|
||||
HashMurmur3TestCase::DoRun (void)
|
||||
{
|
||||
std::string key("The quick brown murmur3.");
|
||||
Hash hasher = Hash ( Create<HashFunction::Murmur3> () );
|
||||
Hasher hasher = Hasher ( Create<Hash::Function::Murmur3> () );
|
||||
|
||||
uint32_t h32r = 0xe8a2d100; // Murmur3(key)
|
||||
uint32_t h32 = hasher.clear ().GetHash32 (key);
|
||||
|
||||
@@ -149,10 +149,10 @@ def build(bld):
|
||||
'model/system-path.cc',
|
||||
'helper/random-variable-stream-helper.cc',
|
||||
'helper/event-garbage-collector.cc',
|
||||
'model/hash.cc',
|
||||
'model/hash-implementation.cc',
|
||||
'model/hash-function.cc',
|
||||
'model/hash-murmur3.cc',
|
||||
'model/hash-fnv.cc',
|
||||
'model/hash.cc',
|
||||
]
|
||||
|
||||
core_test = bld.create_ns3_module_test_library('core')
|
||||
@@ -256,10 +256,10 @@ def build(bld):
|
||||
'model/math.h',
|
||||
'helper/event-garbage-collector.h',
|
||||
'helper/random-variable-stream-helper.h',
|
||||
'model/hash.h',
|
||||
'model/hash-implementation.h',
|
||||
'model/hash-function.h',
|
||||
'model/hash-murmur3.h',
|
||||
'model/hash-fnv.h',
|
||||
'model/hash.h',
|
||||
]
|
||||
|
||||
if sys.platform == 'win32':
|
||||
|
||||
Reference in New Issue
Block a user