A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
hash-function.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2012 Lawrence Livermore National Laboratory
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19
*/
20
21
#ifndef HASHFUNCTION_H
22
#define HASHFUNCTION_H
23
24
#include <cstring>
// memcpy
25
#include "
simple-ref-count.h
"
26
34
namespace
ns3
{
35
40
namespace
Hash {
41
47
class
Implementation
:
public
SimpleRefCount
<Implementation>
48
{
49
public
:
64
virtual
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size) = 0;
81
virtual
uint64_t
GetHash64
(
const
char
* buffer,
const
std::size_t size);
85
virtual
void
clear
(
void
) = 0;
89
Implementation
()
90
{ }
94
virtual
~Implementation
()
95
{ }
96
};
// Hashfunction
97
98
99
/*--------------------------------------
100
* Hash function implementation
101
* by function pointers and templates
102
*/
103
113
typedef
uint32_t (*
Hash32Function_ptr
) (
const
char
*,
const
std::size_t);
114
typedef
uint64_t (*
Hash64Function_ptr
) (
const
char
*,
const
std::size_t);
121
namespace
Function {
122
129
class
Hash32
:
public
Implementation
130
{
131
public
:
137
Hash32
(
Hash32Function_ptr
hp) :
m_fp
(hp)
138
{ }
139
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
140
{
141
return
(*
m_fp
)(buffer, size);
142
}
143
void
clear
()
144
{ }
145
146
private
:
147
Hash32Function_ptr
m_fp
;
148
};
// Hash32
149
156
class
Hash64
:
public
Implementation
157
{
158
public
:
164
Hash64
(
Hash64Function_ptr
hp) :
m_fp
(hp)
165
{ }
166
uint64_t
GetHash64
(
const
char
* buffer,
const
std::size_t size)
167
{
168
return
(*
m_fp
)(buffer, size);
169
}
170
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
171
{
172
uint32_t hash32;
173
uint64_t hash64 =
GetHash64
(buffer, size);
174
175
memcpy (&hash32, &hash64,
sizeof
(hash32));
176
return
hash32;
177
}
178
void
clear
()
179
{ }
180
181
private
:
182
Hash64Function_ptr
m_fp
;
183
};
// Hash64<Hash64Function_ptr>
184
185
186
}
// namespace Function
187
188
}
// namespace Hash
189
190
}
// namespace ns3
191
192
#endif
/* HASHFUNCTION_H */
193
ns3::Hash::Function::Hash32
Template for creating a Hash::Implementation from a 32-bit hash function.
Definition:
hash-function.h:130
ns3::Hash::Function::Hash32::Hash32
Hash32(Hash32Function_ptr hp)
Constructor from a 32-bit hash function pointer.
Definition:
hash-function.h:137
ns3::Hash::Function::Hash32::m_fp
Hash32Function_ptr m_fp
The hash function.
Definition:
hash-function.h:147
ns3::Hash::Function::Hash32::GetHash32
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
Definition:
hash-function.h:139
ns3::Hash::Function::Hash32::clear
void clear()
Restore initial state.
Definition:
hash-function.h:143
ns3::Hash::Function::Hash64
Template for creating a Hash::Implementation from a 64-bit hash function.
Definition:
hash-function.h:157
ns3::Hash::Function::Hash64::m_fp
Hash64Function_ptr m_fp
The hash function.
Definition:
hash-function.h:182
ns3::Hash::Function::Hash64::GetHash32
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
Definition:
hash-function.h:170
ns3::Hash::Function::Hash64::clear
void clear()
Restore initial state.
Definition:
hash-function.h:178
ns3::Hash::Function::Hash64::GetHash64
uint64_t GetHash64(const char *buffer, const std::size_t size)
Compute 64-bit hash of a byte buffer.
Definition:
hash-function.h:166
ns3::Hash::Function::Hash64::Hash64
Hash64(Hash64Function_ptr hp)
Constructor from a 64-bit hash function pointer.
Definition:
hash-function.h:164
ns3::Hash::Implementation
Hash function implementation base class.
Definition:
hash-function.h:48
ns3::Hash::Implementation::Implementation
Implementation()
Constructor.
Definition:
hash-function.h:89
ns3::Hash::Implementation::clear
virtual void clear(void)=0
Restore initial state.
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:38
ns3::Hash::Implementation::~Implementation
virtual ~Implementation()
Destructor.
Definition:
hash-function.h:94
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:73
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:113
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:114
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 Tue Feb 6 2024 19:21:16 for ns-3 by
1.9.1