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
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
18
*/
19
20
#ifndef HASH_FNV_H
21
#define HASH_FNV_H
22
23
#include "
hash-function.h
"
24
25
/**
26
* \file
27
* \ingroup hash
28
* \brief ns3::Hash::Function::Fnv1a declaration.
29
*/
30
31
namespace
ns3
32
{
33
34
namespace
Hash
35
{
36
37
namespace
Function
38
{
39
40
/**
41
* \ingroup hash
42
*
43
* \brief Fnv1a hash function implementation
44
*
45
* This is the venerable Fowler-Noll-Vo hash, version 1A. (See the
46
* <a href="http://isthe.com/chongo/tech/comp/fnv/">FNV page</a>.)
47
*
48
* The implementation here is taken directly from the published FNV
49
* <a href="http://isthe.com/chongo/tech/comp/fnv/#FNV-reference-source">
50
* reference code</a>,
51
* with minor modifications to wrap into this class. See the
52
* hash-fnv.cc file for details.
53
*
54
*/
55
class
Fnv1a
:
public
Implementation
56
{
57
public
:
58
/**
59
* Constructor
60
*/
61
Fnv1a
();
62
/**
63
* Compute 32-bit hash of a byte buffer
64
*
65
* Call clear () between calls to GetHash32() to reset the
66
* internal state and hash each buffer separately.
67
*
68
* If you don't call clear() between calls to GetHash32,
69
* you can hash successive buffers. The final return value
70
* will be the cumulative hash across all calls.
71
*
72
* \param [in] buffer pointer to the beginning of the buffer
73
* \param [in] size length of the buffer, in bytes
74
* \return 32-bit hash of the buffer
75
*/
76
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size)
override
;
77
/**
78
* Compute 64-bit hash of a byte buffer.
79
*
80
* Call clear () between calls to GetHash64() to reset the
81
* internal state and hash each buffer separately.
82
*
83
* If you don't call clear() between calls to GetHash64,
84
* you can hash successive buffers. The final return value
85
* will be the cumulative hash across all calls.
86
*
87
* \param [in] buffer pointer to the beginning of the buffer
88
* \param [in] size length of the buffer, in bytes
89
* \return 64-bit hash of the buffer
90
*/
91
uint64_t
GetHash64
(
const
char
* buffer,
const
size_t
size)
override
;
92
/**
93
* Restore initial state
94
*/
95
void
clear
()
override
;
96
97
private
:
98
/**
99
* Seed value
100
*/
101
static
constexpr
auto
SEED
{0x8BADF00D};
// Ate bad food
102
103
/** Cache last hash value, for incremental hashing. */
104
/**@{*/
105
uint32_t
m_hash32
;
106
uint64_t
m_hash64
;
107
/**@}*/
108
109
};
// class Fnv1a
110
111
}
// namespace Function
112
113
}
// namespace Hash
114
115
}
// namespace ns3
116
117
#endif
/* HASH_FNV_H */
ns3::Hash::Function::Fnv1a
Fnv1a hash function implementation.
Definition:
hash-fnv.h:56
ns3::Hash::Function::Fnv1a::m_hash32
uint32_t m_hash32
Cache last hash value, for incremental hashing.
Definition:
hash-fnv.h:105
ns3::Hash::Function::Fnv1a::SEED
static constexpr auto SEED
Seed value.
Definition:
hash-fnv.h:101
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:763
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:770
ns3::Hash::Function::Fnv1a::m_hash64
uint64_t m_hash64
Cache last hash value, for incremental hashing.
Definition:
hash-fnv.h:106
ns3::Hash::Function::Fnv1a::Fnv1a
Fnv1a()
Constructor.
Definition:
hash-fnv.cc:757
ns3::Hash::Function::Fnv1a::clear
void clear() override
Restore initial state.
Definition:
hash-fnv.cc:777
ns3::Hash::Implementation
Hash function implementation base class.
Definition:
hash-function.h:50
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 Tue May 28 2024 23:34:31 for ns-3 by
1.9.6