Fnv1a hash function implementation. More...
#include "hash-fnv.h"
Public Member Functions | |
Fnv1a () | |
Constructor. | |
void | clear () override |
Restore initial state. | |
uint32_t | GetHash32 (const char *buffer, const size_t size) override |
Compute 32-bit hash of a byte buffer. | |
uint64_t | GetHash64 (const char *buffer, const size_t size) override |
Compute 64-bit hash of a byte buffer. | |
Public Member Functions inherited from ns3::Hash::Implementation | |
Implementation () | |
Constructor. | |
virtual | ~Implementation () |
Destructor. | |
virtual uint32_t | GetHash32 (const char *buffer, const std::size_t size)=0 |
Compute 32-bit hash of a byte buffer. | |
virtual uint64_t | GetHash64 (const char *buffer, const std::size_t size) |
Compute 64-bit hash of a byte buffer. | |
Public Member Functions inherited from ns3::SimpleRefCount< Implementation > | |
SimpleRefCount () | |
Default constructor. | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment operator. | |
void | Ref () const |
Increment the reference count. | |
void | Unref () const |
Decrement the reference count. | |
Private Attributes | |
uint32_t | m_hash32 |
Cache last hash value, for incremental hashing. | |
uint64_t | m_hash64 |
Cache last hash value, for incremental hashing. | |
Static Private Attributes | |
static constexpr auto | SEED {0x8BADF00D} |
Seed value. | |
Fnv1a hash function implementation.
This is the venerable Fowler-Noll-Vo hash, version 1A. (See the FNV page.)
The implementation here is taken directly from the published FNV reference code, with minor modifications to wrap into this class. See the hash-fnv.cc file for details.
Definition at line 44 of file hash-fnv.h.
ns3::Hash::Function::Fnv1a::Fnv1a | ( | ) |
Constructor.
Definition at line 746 of file hash-fnv.cc.
References clear().
|
overridevirtual |
Restore initial state.
Implements ns3::Hash::Implementation.
Definition at line 766 of file hash-fnv.cc.
References FNV1_32A_INIT, FNV1A_64_INIT, m_hash32, and m_hash64.
Referenced by Fnv1a().
|
override |
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.
[in] | buffer | pointer to the beginning of the buffer |
[in] | size | length of the buffer, in bytes |
Definition at line 752 of file hash-fnv.cc.
References ns3::Hash::Function::Fnv1aImplementation::fnv_32a_buf(), and m_hash32.
|
override |
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.
[in] | buffer | pointer to the beginning of the buffer |
[in] | size | length of the buffer, in bytes |
Definition at line 759 of file hash-fnv.cc.
References ns3::Hash::Function::Fnv1aImplementation::fnv_64a_buf(), and m_hash64.
|
private |
Cache last hash value, for incremental hashing.
Definition at line 94 of file hash-fnv.h.
Referenced by clear(), and GetHash32().
|
private |
Cache last hash value, for incremental hashing.
Definition at line 95 of file hash-fnv.h.
Referenced by clear(), and GetHash64().
|
staticconstexprprivate |
Seed value.
Definition at line 90 of file hash-fnv.h.