A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
hash-function.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 HASHFUNCTION_H
21
#define HASHFUNCTION_H
22
23
#include "
simple-ref-count.h
"
24
25
#include <cstring>
// memcpy
26
34
namespace
ns3
35
{
36
41
namespace
Hash
42
{
43
49
class
Implementation
:
public
SimpleRefCount
<Implementation>
50
{
51
public
:
66
virtual
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size) = 0;
83
virtual
uint64_t
GetHash64
(
const
char
* buffer,
const
std::size_t size);
87
virtual
void
clear
() = 0;
88
92
Implementation
()
93
{
94
}
95
99
virtual
~Implementation
()
100
{
101
}
102
};
// Hashfunction
103
104
/*--------------------------------------
105
* Hash function implementation
106
* by function pointers and templates
107
*/
108
118
typedef
uint32_t (*
Hash32Function_ptr
)(
const
char
*,
const
std::size_t);
119
typedef
uint64_t (*
Hash64Function_ptr
)(
const
char
*,
const
std::size_t);
120
127
namespace
Function
128
{
129
136
class
Hash32
:
public
Implementation
137
{
138
public
:
144
Hash32
(
Hash32Function_ptr
hp)
145
:
m_fp
(hp)
146
{
147
}
148
149
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
override
150
{
151
return
(*
m_fp
)(buffer, size);
152
}
153
154
void
clear
()
override
155
{
156
}
157
158
private
:
159
Hash32Function_ptr
m_fp
;
160
};
// Hash32
161
168
class
Hash64
:
public
Implementation
169
{
170
public
:
176
Hash64
(
Hash64Function_ptr
hp)
177
:
m_fp
(hp)
178
{
179
}
180
181
uint64_t
GetHash64
(
const
char
* buffer,
const
std::size_t size)
override
182
{
183
return
(*
m_fp
)(buffer, size);
184
}
185
186
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
override
187
{
188
uint32_t hash32;
189
uint64_t hash64 =
GetHash64
(buffer, size);
190
191
memcpy(&hash32, &hash64,
sizeof
(hash32));
192
return
hash32;
193
}
194
195
void
clear
()
override
196
{
197
}
198
199
private
:
200
Hash64Function_ptr
m_fp
;
201
};
// Hash64<Hash64Function_ptr>
202
203
}
// namespace Function
204
205
}
// namespace Hash
206
207
}
// namespace ns3
208
209
#endif
/* HASHFUNCTION_H */
ns3::Hash::Function::Hash32
Template for creating a Hash::Implementation from a 32-bit hash function.
Definition:
hash-function.h:137
ns3::Hash::Function::Hash32::clear
void clear() override
Restore initial state.
Definition:
hash-function.h:154
ns3::Hash::Function::Hash32::Hash32
Hash32(Hash32Function_ptr hp)
Constructor from a 32-bit hash function pointer.
Definition:
hash-function.h:144
ns3::Hash::Function::Hash32::GetHash32
uint32_t GetHash32(const char *buffer, const std::size_t size) override
Compute 32-bit hash of a byte buffer.
Definition:
hash-function.h:149
ns3::Hash::Function::Hash32::m_fp
Hash32Function_ptr m_fp
The hash function.
Definition:
hash-function.h:159
ns3::Hash::Function::Hash64
Template for creating a Hash::Implementation from a 64-bit hash function.
Definition:
hash-function.h:169
ns3::Hash::Function::Hash64::clear
void clear() override
Restore initial state.
Definition:
hash-function.h:195
ns3::Hash::Function::Hash64::m_fp
Hash64Function_ptr m_fp
The hash function.
Definition:
hash-function.h:200
ns3::Hash::Function::Hash64::GetHash64
uint64_t GetHash64(const char *buffer, const std::size_t size) override
Compute 64-bit hash of a byte buffer.
Definition:
hash-function.h:181
ns3::Hash::Function::Hash64::GetHash32
uint32_t GetHash32(const char *buffer, const std::size_t size) override
Compute 32-bit hash of a byte buffer.
Definition:
hash-function.h:186
ns3::Hash::Function::Hash64::Hash64
Hash64(Hash64Function_ptr hp)
Constructor from a 64-bit hash function pointer.
Definition:
hash-function.h:176
ns3::Hash::Implementation
Hash function implementation base class.
Definition:
hash-function.h:50
ns3::Hash::Implementation::Implementation
Implementation()
Constructor.
Definition:
hash-function.h:92
ns3::Hash::Implementation::GetHash64
virtual uint64_t GetHash64(const char *buffer, const std::size_t size)
Compute 64-bit hash of a byte buffer.
Definition:
hash-function.cc:39
ns3::Hash::Implementation::~Implementation
virtual ~Implementation()
Destructor.
Definition:
hash-function.h:99
ns3::Hash::Implementation::clear
virtual void clear()=0
Restore initial state.
ns3::Hash::Implementation::GetHash32
virtual uint32_t GetHash32(const char *buffer, const std::size_t size)=0
Compute 32-bit hash of a byte buffer.
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:81
ns3::Hash::Hash32Function_ptr
uint32_t(* Hash32Function_ptr)(const char *, const std::size_t)
Function pointer signatures for basic hash functions.
Definition:
hash-function.h:118
ns3::Hash::Hash64Function_ptr
uint64_t(* Hash64Function_ptr)(const char *, const std::size_t)
Function pointer signatures for basic hash functions.
Definition:
hash-function.h:119
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
simple-ref-count.h
ns3::SimpleRefCount declaration and template implementation.
src
core
model
hash-function.h
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1