A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::Hasher Class Reference

Generic Hash function interface. More...

#include <hash.h>

+ Collaboration diagram for ns3::Hasher:

Public Member Functions

 Hasher ()
 Constructor using the default implementation. More...
 
 Hasher (Ptr< Hash::Implementation > hp)
 Constructor using the supplied implementation. More...
 
Hasherclear (void)
 Restore initial state. More...
 
uint32_t GetHash32 (const char *buffer, const size_t size)
 Compute 32-bit hash of a byte buffer. More...
 
uint32_t GetHash32 (const std::string s)
 Compute 32-bit hash of a string. More...
 
uint64_t GetHash64 (const char *buffer, const size_t size)
 Compute 64-bit hash of a byte buffer. More...
 
uint64_t GetHash64 (const std::string s)
 Compute 64-bit hash of a string. More...
 

Private Attributes

Ptr< Hash::Implementationm_impl
 

Detailed Description

Generic Hash function interface.

This class provides a generic interface for computing hashes of buffers. Various getters return hashes of different lengths.

Call clear() between calls to the getter to reset the internal state and hash each buffer separately.

If you don't call clear() between calls to the getter you can hash successive buffers. The final return value will be the cumulative hash across all calls.

The choice of hash function can be made at construction by

Hasher hasher = Hasher ( Create<Hash::Function::Fnv1a> () );
uint32_t hash = Hasher.GetHash32 (data);

The available implementations are documented in group hash. The default implementation is Murmur3. FNV1a is also available.

In addition to this class interface, global functions are defined which use the default hash implementation.

Internal:

Would be nice to offer longer hashes. uint128_t looks doable, except that our fallback int64x64_t implementation doesn't offer unsigned.

Longer hashes require returning a byte buffer of some sort, but our Buffer class seems a bit overkill for this case.

Definition at line 78 of file hash.h.

Constructor & Destructor Documentation

ns3::Hasher::Hasher ( )

Constructor using the default implementation.

Definition at line 29 of file hash.cc.

References m_impl, and NS_ASSERT.

ns3::Hasher::Hasher ( Ptr< Hash::Implementation hp)

Constructor using the supplied implementation.

Parameters
[in]hpPtr<Hash::Implementation> to the desired implementation

Definition at line 35 of file hash.cc.

References m_impl, and NS_ASSERT.

Member Function Documentation

Hasher & ns3::Hasher::clear ( void  )
uint32_t ns3::Hasher::GetHash32 ( const char *  buffer,
const size_t  size 
)
inline

Compute 32-bit hash of a byte buffer.

Call clear () between calls to GetHash32() to reset the internal state and hash each buffer separately.

If you don't call clear() between calls to GetHash32, you can hash successive buffers. The final return value will be the cumulative hash across all calls.

Parameters
[in]bufferpointer to the beginning of the buffer
[in]sizelength of the buffer, in bytes
Returns
32-bit hash of the buffer

Definition at line 221 of file hash.h.

References ns3::Hash::Implementation::GetHash32(), m_impl, and NS_ASSERT.

Referenced by IncrementalTestCase::DoHash(), UniqueTypeIdTestCase::DoRun(), Fnv1aTestCase::DoRun(), Murmur3TestCase::DoRun(), Hash32FunctionPtrTestCase::DoRun(), ns3::Hash::Example::Collider::GetHash(), ns3::Hash32(), ns3::IidManager::Hasher(), and ns3::Hash::Example::Dictionary::TimeOne().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32_t ns3::Hasher::GetHash32 ( const std::string  s)
inline

Compute 32-bit hash of a string.

Call clear () between calls to GetHash32() to reset the internal state and hash each string separately.

If you don't call clear() between calls to GetHash32, you can hash successive strings. The final return value will be the cumulative hash across all calls.

Parameters
[in]sstring to hash
Returns
32-bit hash of the string

Definition at line 237 of file hash.h.

References ns3::Hash::Implementation::GetHash32(), m_impl, and NS_ASSERT.

+ Here is the call graph for this function:

uint64_t ns3::Hasher::GetHash64 ( const char *  buffer,
const size_t  size 
)
inline

Compute 64-bit hash of a byte buffer.

Call clear () between calls to GetHash64() to reset the internal state and hash each buffer separately.

If you don't call clear() between calls to GetHash64, you can hash successive buffers. The final return value will be the cumulative hash across all calls.

Parameters
[in]bufferpointer to the beginning of the buffer
[in]sizelength of the buffer, in bytes
Returns
64-bit hash of the buffer

Definition at line 229 of file hash.h.

References ns3::Hash::Implementation::GetHash64(), m_impl, and NS_ASSERT.

Referenced by IncrementalTestCase::DoHash(), Fnv1aTestCase::DoRun(), Murmur3TestCase::DoRun(), Hash64FunctionPtrTestCase::DoRun(), ns3::Hash::Example::Collider::GetHash(), and ns3::Hash64().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint64_t ns3::Hasher::GetHash64 ( const std::string  s)
inline

Compute 64-bit hash of a string.

Call clear () between calls to GetHash64() to reset the internal state and hash each string separately.

If you don't call clear() between calls to GetHash64, you can hash successive strings. The final return value will be the cumulative hash across all calls.

Parameters
[in]sstring to hash
Returns
64-bit hash of the string

Definition at line 245 of file hash.h.

References ns3::Hash::Implementation::GetHash64(), m_impl, and NS_ASSERT.

+ Here is the call graph for this function:

Member Data Documentation

Ptr<Hash::Implementation> ns3::Hasher::m_impl
private

Definition at line 158 of file hash.h.

Referenced by clear(), GetHash32(), GetHash64(), and Hasher().


The documentation for this class was generated from the following files: