A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
model
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
() { };
93
virtual
~Implementation
() { };
94
};
// Hashfunction
95
96
97
/*--------------------------------------
98
* Hash function implementation
99
* by function pointers and templates
100
*/
101
111
typedef
uint32_t (*
Hash32Function_ptr
) (
const
char
*,
const
std::size_t);
112
typedef
uint64_t (*
Hash64Function_ptr
) (
const
char
*,
const
std::size_t);
119
namespace
Function {
120
127
class
Hash32
:
public
Implementation
128
{
129
public
:
135
Hash32
(
Hash32Function_ptr
hp) :
m_fp
(hp) { };
136
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
137
{
138
return
(*
m_fp
) (buffer, size);
139
}
140
void
clear
() { };
141
private
:
142
Hash32Function_ptr
m_fp
;
143
};
// Hash32
144
151
class
Hash64
:
public
Implementation
152
{
153
public
:
159
Hash64
(
Hash64Function_ptr
hp) :
m_fp
(hp) { };
160
uint64_t
GetHash64
(
const
char
* buffer,
const
std::size_t size)
161
{
162
return
(*
m_fp
) (buffer, size);
163
}
164
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
165
{
166
uint32_t hash32;
167
uint64_t hash64 =
GetHash64
(buffer, size);
168
169
memcpy (&hash32, &hash64,
sizeof
(hash32));
170
return
hash32;
171
}
172
void
clear
() { };
173
private
:
174
Hash64Function_ptr
m_fp
;
175
};
// Hash64<Hash64Function_ptr>
176
177
178
}
// namespace Function
179
180
}
// namespace Hash
181
182
}
// namespace ns3
183
184
#endif
/* HASHFUNCTION_H */
185
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:111
ns3::Hash::Implementation::Implementation
Implementation()
Constructor.
Definition:
hash-function.h:89
ns3::Hash::Implementation::~Implementation
virtual ~Implementation()
Destructor.
Definition:
hash-function.h:93
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
Hash function implementation base class.
Definition:
hash-function.h:47
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::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:136
ns3::Hash::Function::Hash32::Hash32
Hash32(Hash32Function_ptr hp)
Constructor from a 32-bit hash function pointer.
Definition:
hash-function.h:135
ns3::Hash::Function::Hash64::clear
void clear()
Restore initial state.
Definition:
hash-function.h:172
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:164
ns3::Hash::Function::Hash32
Template for creating a Hash::Implementation from a 32-bit hash function.
Definition:
hash-function.h:127
ns3::Hash::Implementation::clear
virtual void clear(void)=0
Restore initial state.
ns3::Hash::Function::Hash32::m_fp
Hash32Function_ptr m_fp
The hash function.
Definition:
hash-function.h:140
ns3::Hash::Function::Hash64
Template for creating a Hash::Implementation from a 64-bit hash function.
Definition:
hash-function.h:151
ns3::Hash::Function::Hash64::m_fp
Hash64Function_ptr m_fp
The hash function.
Definition:
hash-function.h:172
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:73
ns3::Hash::Function::Hash32::clear
void clear()
Restore initial state.
Definition:
hash-function.h:140
ns3::Hash::Function::Hash64::Hash64
Hash64(Hash64Function_ptr hp)
Constructor from a 64-bit hash function pointer.
Definition:
hash-function.h:159
simple-ref-count.h
ns3::SimpleRefCount declaration and template implementation.
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:112
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:160
Generated on Wed Nov 7 2018 10:01:49 for ns-3 by
1.8.14