A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
hash-fnv.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012 Lawrence Livermore National Laboratory
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7
*/
8
9
#ifndef HASH_FNV_H
10
#define HASH_FNV_H
11
12
#include "
hash-function.h
"
13
14
/**
15
* \file
16
* \ingroup hash
17
* \brief ns3::Hash::Function::Fnv1a declaration.
18
*/
19
20
namespace
ns3
21
{
22
23
namespace
Hash
24
{
25
26
namespace
Function
27
{
28
29
/**
30
* \ingroup hash
31
*
32
* \brief Fnv1a hash function implementation
33
*
34
* This is the venerable Fowler-Noll-Vo hash, version 1A. (See the
35
* <a href="http://isthe.com/chongo/tech/comp/fnv/">FNV page</a>.)
36
*
37
* The implementation here is taken directly from the published FNV
38
* <a href="http://isthe.com/chongo/tech/comp/fnv/#FNV-reference-source">
39
* reference code</a>,
40
* with minor modifications to wrap into this class. See the
41
* hash-fnv.cc file for details.
42
*
43
*/
44
class
Fnv1a
:
public
Implementation
45
{
46
public
:
47
/**
48
* Constructor
49
*/
50
Fnv1a
();
51
/**
52
* Compute 32-bit hash of a byte buffer
53
*
54
* Call clear () between calls to GetHash32() to reset the
55
* internal state and hash each buffer separately.
56
*
57
* If you don't call clear() between calls to GetHash32,
58
* you can hash successive buffers. The final return value
59
* will be the cumulative hash across all calls.
60
*
61
* \param [in] buffer pointer to the beginning of the buffer
62
* \param [in] size length of the buffer, in bytes
63
* \return 32-bit hash of the buffer
64
*/
65
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size)
override
;
66
/**
67
* Compute 64-bit hash of a byte buffer.
68
*
69
* Call clear () between calls to GetHash64() to reset the
70
* internal state and hash each buffer separately.
71
*
72
* If you don't call clear() between calls to GetHash64,
73
* you can hash successive buffers. The final return value
74
* will be the cumulative hash across all calls.
75
*
76
* \param [in] buffer pointer to the beginning of the buffer
77
* \param [in] size length of the buffer, in bytes
78
* \return 64-bit hash of the buffer
79
*/
80
uint64_t
GetHash64
(
const
char
* buffer,
const
size_t
size)
override
;
81
/**
82
* Restore initial state
83
*/
84
void
clear
()
override
;
85
86
private
:
87
/**
88
* Seed value
89
*/
90
static
constexpr
auto
SEED
{0x8BADF00D};
// Ate bad food
91
92
/** Cache last hash value, for incremental hashing. */
93
/**@{*/
94
uint32_t
m_hash32
;
95
uint64_t
m_hash64
;
96
/**@}*/
97
98
};
// class Fnv1a
99
100
}
// namespace Function
101
102
}
// namespace Hash
103
104
}
// namespace ns3
105
106
#endif
/* HASH_FNV_H */
ns3::Hash::Function::Fnv1a
Fnv1a hash function implementation.
Definition
hash-fnv.h:45
ns3::Hash::Function::Fnv1a::m_hash32
uint32_t m_hash32
Cache last hash value, for incremental hashing.
Definition
hash-fnv.h:94
ns3::Hash::Function::Fnv1a::SEED
static constexpr auto SEED
Seed value.
Definition
hash-fnv.h:90
ns3::Hash::Function::Fnv1a::GetHash32
uint32_t GetHash32(const char *buffer, const size_t size) override
Compute 32-bit hash of a byte buffer.
Definition
hash-fnv.cc:752
ns3::Hash::Function::Fnv1a::GetHash64
uint64_t GetHash64(const char *buffer, const size_t size) override
Compute 64-bit hash of a byte buffer.
Definition
hash-fnv.cc:759
ns3::Hash::Function::Fnv1a::m_hash64
uint64_t m_hash64
Cache last hash value, for incremental hashing.
Definition
hash-fnv.h:95
ns3::Hash::Function::Fnv1a::Fnv1a
Fnv1a()
Constructor.
Definition
hash-fnv.cc:746
ns3::Hash::Function::Fnv1a::clear
void clear() override
Restore initial state.
Definition
hash-fnv.cc:766
ns3::Hash::Implementation
Hash function implementation base class.
Definition
hash-function.h:39
uint32_t
hash-function.h
ns3::Hash::Implementation, ns3::Hash::Function::Hash32 and ns3::Hash::Function::Hash64 declarations.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
model
hash-fnv.h
Generated on Wed Oct 9 2024 01:03:22 for ns-3 by
1.11.0