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
39
namespace
ns3 {
40
87
class
Hasher
88
{
89
public
:
93
Hasher
();
99
Hasher
(
Ptr<Hash::Implementation>
hp);
114
uint32_t
GetHash32
(
const
char
* buffer,
const
size_t
size);
129
uint64_t
GetHash64
(
const
char
* buffer,
const
size_t
size);
130
144
uint32_t
GetHash32
(
const
std::string s);
158
uint64_t
GetHash64
(
const
std::string s);
173
Hasher
&
clear
(
void
);
174
175
private
:
176
Ptr<Hash::Implementation>
m_impl
;
177
};
// Hasher
178
179
180
/*************************************************
181
** Global functions declarations
182
************************************************/
183
193
uint32_t
Hash32
(
const
char
* buffer,
const
size_t
size);
203
uint64_t
Hash64
(
const
char
* buffer,
const
size_t
size);
204
213
uint32_t
Hash32
(
const
std::string s);
222
uint64_t
Hash64
(
const
std::string s);
223
224
}
// namespace ns3
225
226
227
/*************************************************
228
** Inline implementations for rvo
229
************************************************/
230
231
namespace
ns3 {
232
233
/*************************************************
234
class Hasher implementation, inlined for rvo
235
*/
236
237
inline
238
uint32_t
239
Hasher::GetHash32
(
const
char
* buffer,
const
size_t
size)
240
{
241
NS_ASSERT
(
m_impl
!= 0);
242
return
m_impl
->
GetHash32
(buffer, size);
243
}
244
245
inline
246
uint64_t
247
Hasher::GetHash64
(
const
char
* buffer,
const
size_t
size)
248
{
249
NS_ASSERT
(
m_impl
!= 0);
250
return
m_impl
->
GetHash64
(buffer, size);
251
}
252
253
inline
254
uint32_t
255
Hasher::GetHash32
(
const
std::string s)
256
{
257
NS_ASSERT
(
m_impl
!= 0);
258
return
m_impl
->
GetHash32
(s.c_str (), s.size ());
259
}
260
261
inline
262
uint64_t
263
Hasher::GetHash64
(
const
std::string s)
264
{
265
NS_ASSERT
(
m_impl
!= 0);
266
return
m_impl
->
GetHash64
(s.c_str (), s.size ());
267
}
268
269
270
/*************************************************
271
Global hash functions, inlined for rvo
272
*/
273
274
inline
275
uint32_t
276
Hash32
(
const
char
* buffer,
const
size_t
size)
277
{
278
return
Hasher
().
GetHash32
(buffer, size);
279
}
280
281
inline
282
uint64_t
283
Hash64
(
const
char
* buffer,
const
size_t
size)
284
{
285
return
Hasher
().
GetHash64
(buffer, size);
286
}
287
288
inline
289
uint32_t
290
Hash32
(
const
std::string s)
291
{
292
return
Hasher
().
GetHash32
(s);
293
}
294
295
inline
296
uint64_t
297
Hash64
(
const
std::string s)
298
{
299
return
Hasher
().
GetHash64
(s);
300
}
301
302
303
}
// namespace ns3
304
305
#endif
/* HASH_H */
ns3::Ptr< Hash::Implementation >
hash-function.h
ns3::Hash::Implementation, ns3::Hash::Function::Hash32 and ns3::Hash::Function::Hash64 declarations...
ptr.h
Smart pointer implementation.
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition:
assert.h:67
hash-fnv.h
ns3::Hash::Function::Fnv1a declaration.
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:38
assert.h
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
ns3::Hasher::Hasher
Hasher()
Constructor using the default implementation.
Definition:
hash.cc:35
ns3::Hasher::GetHash32
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Definition:
hash.h:239
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:276
ns3::Hasher::clear
Hasher & clear(void)
Restore initial state.
Definition:
hash.cc:48
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:283
ns3::Hasher::m_impl
Ptr< Hash::Implementation > m_impl
Hash implementation.
Definition:
hash.h:176
ns3::Hasher::GetHash64
uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
Definition:
hash.h:247
hash-murmur3.h
ns3::Hash::Function::Murmur3 declaration.
ns3::Hasher
Generic Hash function interface.
Definition:
hash.h:87
src
core
model
hash.h
Generated on Wed Jul 6 2016 17:11:26 for ns-3 by
1.8.6