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.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 HASH_H
22
#define HASH_H
23
24
#include <string>
25
26
#include "
assert.h
"
27
#include "
ptr.h
"
28
29
#include "
hash-function.h
"
30
#include "
hash-murmur3.h
"
31
#include "
hash-fnv.h
"
32
33
namespace
ns3 {
34
76
class
Hasher
77
{
78
public
:
82
Hasher
();
88
Hasher
(
Ptr<Hash::Implementation>
hp);
103
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size);
118
uint64_t
GetHash64
(
const
char
* buffer,
const
size_t
size);
119
133
uint32_t
GetHash32
(
const
std::string
s
);
147
uint64_t
GetHash64
(
const
std::string s);
153
Hasher
&
clear
(
void
);
154
155
private
:
156
Ptr<Hash::Implementation>
m_impl
;
157
};
// Hasher
158
159
160
/*************************************************
161
** Global functions declarations
162
************************************************/
163
173
uint32_t
Hash32
(
const
char
* buffer,
const
size_t
size);
183
uint64_t
Hash64
(
const
char
* buffer,
const
size_t
size);
184
193
uint32_t
Hash32
(
const
std::string
s
);
202
uint64_t
Hash64
(
const
std::string
s
);
203
204
}
// namespace ns3
205
206
207
/*************************************************
208
** Inline implementations for rvo
209
************************************************/
210
211
namespace
ns3 {
212
213
/*************************************************
214
class Hasher implementation, inlined for rvo
215
*/
216
217
inline
218
uint32_t
219
Hasher::GetHash32
(
const
char
* buffer,
const
size_t
size)
220
{
221
NS_ASSERT
(
m_impl
!= 0);
222
return
m_impl
->
GetHash32
(buffer, size);
223
}
224
225
inline
226
uint64_t
227
Hasher::GetHash64
(
const
char
* buffer,
const
size_t
size)
228
{
229
NS_ASSERT
(
m_impl
!= 0);
230
return
m_impl
->
GetHash64
(buffer, size);
231
}
232
233
inline
234
uint32_t
235
Hasher::GetHash32
(
const
std::string
s
)
236
{
237
NS_ASSERT
(
m_impl
!= 0);
238
return
m_impl
->
GetHash32
(s.c_str (), s.size ());
239
}
240
241
inline
242
uint64_t
243
Hasher::GetHash64
(
const
std::string
s
)
244
{
245
NS_ASSERT
(
m_impl
!= 0);
246
return
m_impl
->
GetHash64
(s.c_str (), s.size ());
247
}
248
249
250
/*************************************************
251
Global hash functions, inlined for rvo
252
*/
253
254
inline
255
uint32_t
256
Hash32
(
const
char
* buffer,
const
size_t
size)
257
{
258
return
Hasher
().
GetHash32
(buffer, size);
259
}
260
261
inline
262
uint64_t
263
Hash64
(
const
char
* buffer,
const
size_t
size)
264
{
265
return
Hasher
().
GetHash64
(buffer, size);
266
}
267
268
inline
269
uint32_t
270
Hash32
(
const
std::string
s
)
271
{
272
return
Hasher
().
GetHash32
(s);
273
}
274
275
inline
276
uint64_t
277
Hash64
(
const
std::string
s
)
278
{
279
return
Hasher
().
GetHash64
(s);
280
}
281
282
283
}
// namespace ns3
284
285
#endif
/* HASH_H */
ns3::Ptr< Hash::Implementation >
hash-function.h
ptr.h
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
hash-fnv.h
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
assert.h
ns3::Hasher::Hasher
Hasher()
Constructor using the default implementation.
Definition:
hash.cc:30
s
Ptr< SampleEmitter > s
Definition:
double-probe-test-suite.cc:51
ns3::Hasher::GetHash32
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Definition:
hash.h:219
ns3::Hash32
uint32_t Hash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer, using the default hash function.
Definition:
hash.h:256
ns3::Hasher::clear
Hasher & clear(void)
Restore initial state.
Definition:
hash.cc:43
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::Hash64
uint64_t Hash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer, using the default hash function.
Definition:
hash.h:263
ns3::Hasher::m_impl
Ptr< Hash::Implementation > m_impl
Definition:
hash.h:156
ns3::Hasher::GetHash64
uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
Definition:
hash.h:227
hash-murmur3.h
ns3::Hasher
Generic Hash function interface.
Definition:
hash.h:76
src
core
model
hash.h
Generated on Sat Apr 19 2014 14:06:51 for ns-3 by
1.8.6