A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
27
namespace
ns3 {
28
33
namespace
Hash {
34
40
class
Implementation
:
public
SimpleRefCount
<Implementation>
41
{
42
public
:
57
virtual
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size) = 0;
74
virtual
uint64_t
GetHash64
(
const
char
* buffer,
const
size_t
size);
78
virtual
void
clear
(
void
) = 0;
82
Implementation
() { };
86
virtual
~Implementation
() { };
87
};
// Hashfunction
88
89
90
/*--------------------------------------
91
* Hash function implementation
92
* by function pointers and templates
93
*/
94
104
typedef
uint32_t (*
Hash32Function_ptr
) (
const
char
*,
const
size_t);
105
typedef
uint64_t (*
Hash64Function_ptr
) (
const
char
*,
const
size_t);
112
namespace
Function {
113
119
class
Hash32
:
public
Implementation
120
{
121
public
:
122
Hash32
(
Hash32Function_ptr
hp) :
m_fp
(hp) { };
123
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size)
124
{
125
return
(*
m_fp
) (buffer, size);
126
}
127
void
clear
() { };
128
private
:
129
Hash32Function_ptr
m_fp
;
130
};
// Hash32
131
137
class
Hash64
:
public
Implementation
138
{
139
public
:
140
Hash64
(
Hash64Function_ptr
hp) :
m_fp
(hp) { };
141
uint64_t
GetHash64
(
const
char
* buffer,
const
size_t
size)
142
{
143
return
(*
m_fp
) (buffer, size);
144
}
145
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size)
146
{
147
uint32_t hash32;
148
uint64_t hash64 =
GetHash64
(buffer, size);
149
150
memcpy (&hash32, &hash64,
sizeof
(hash32));
151
return
hash32;
152
}
153
void
clear
() { };
154
private
:
155
Hash64Function_ptr
m_fp
;
156
};
// Hash64<Hash64Function_ptr>
157
158
159
}
// namespace Function
160
161
}
// namespace Hash
162
163
}
// namespace ns3
164
165
#endif
/* HASHFUNCTION_H */
166
ns3::Hash::Implementation::Implementation
Implementation()
Constructor.
Definition:
hash-function.h:82
ns3::Hash::Implementation::~Implementation
virtual ~Implementation()
Destructor.
Definition:
hash-function.h:86
ns3::Hash::Function::Hash32::GetHash32
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Definition:
hash-function.h:123
ns3::Hash::Hash64Function_ptr
uint64_t(* Hash64Function_ptr)(const char *, const size_t)
Basic hash function typedefs.
Definition:
hash-function.h:105
ns3::Hash::Implementation
Hash function implementation base class.
Definition:
hash-function.h:40
ns3::Hash::Implementation::GetHash64
virtual uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
Definition:
hash-function.cc:33
ns3::Hash::Function::Hash32::Hash32
Hash32(Hash32Function_ptr hp)
Definition:
hash-function.h:122
ns3::Hash::Function::Hash64::clear
void clear()
Restore initial state.
Definition:
hash-function.h:153
ns3::Hash::Function::Hash32
Template for Hashfunctions from 32-bit hash functions.
Definition:
hash-function.h:119
ns3::Hash::Implementation::clear
virtual void clear(void)=0
Restore initial state.
ns3::Hash::Implementation::GetHash32
virtual uint32_t GetHash32(const char *buffer, const size_t size)=0
Compute 32-bit hash of a byte buffer.
ns3::Hash::Function::Hash64::GetHash64
uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
Definition:
hash-function.h:141
ns3::Hash::Hash32Function_ptr
uint32_t(* Hash32Function_ptr)(const char *, const size_t)
Basic hash function typedefs.
Definition:
hash-function.h:104
ns3::Hash::Function::Hash32::m_fp
Hash32Function_ptr m_fp
Definition:
hash-function.h:127
ns3::Hash::Function::Hash64
Template for Hashfunctions from 64-bit hash functions.
Definition:
hash-function.h:137
ns3::Hash::Function::Hash64::m_fp
Hash64Function_ptr m_fp
Definition:
hash-function.h:153
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:64
ns3::Hash::Function::Hash32::clear
void clear()
Restore initial state.
Definition:
hash-function.h:127
ns3::Hash::Function::Hash64::Hash64
Hash64(Hash64Function_ptr hp)
Definition:
hash-function.h:140
simple-ref-count.h
ns3::Hash::Function::Hash64::GetHash32
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Definition:
hash-function.h:145
src
core
model
hash-function.h
Generated on Sat Apr 19 2014 14:06:51 for ns-3 by
1.8.6