A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
hash-murmur3.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012 Lawrence Livermore National Laboratory
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7
*/
8
9
#ifndef HASH_MURMUR3_H
10
#define HASH_MURMUR3_H
11
12
#include "
hash-function.h
"
13
14
/**
15
* \file
16
* \ingroup hash
17
* \brief ns3::Hash::Function::Murmur3 declaration.
18
*/
19
20
namespace
ns3
21
{
22
23
namespace
Hash
24
{
25
26
namespace
Function
27
{
28
29
/**
30
* \ingroup hash
31
*
32
* \brief Murmur3 hash function implementation
33
*
34
* Adapted from http://code.google.com/p/smhasher/
35
*
36
* MurmurHash3 was written by Austin Appleby, and is placed in the public
37
* domain. The author hereby disclaims copyright to this source code.
38
39
* Note - The x86 and x64 versions do _not_ produce the same results, as the
40
* algorithms are optimized for their respective platforms. You can still
41
* compile and run any of them on any platform, but your performance with the
42
* non-native version will be less than optimal.
43
*/
44
class
Murmur3
:
public
Implementation
45
{
46
public
:
47
/**
48
* Constructor, clears internal state
49
*/
50
Murmur3
();
51
/**
52
* Compute 32-bit hash of a byte buffer
53
*
54
* Call clear () between calls to GetHash32() to reset the
55
* internal state and hash each buffer separately.
56
*
57
* If you don't call clear() between calls to GetHash32,
58
* you can hash successive buffers. The final return value
59
* will be the cumulative hash across all calls.
60
*
61
* \param [in] buffer pointer to the beginning of the buffer
62
* \param [in] size length of the buffer, in bytes
63
* \return 32-bit hash of the buffer
64
*/
65
uint32_t
GetHash32
(
const
char
* buffer,
const
std::size_t size)
override
;
66
/**
67
* Compute 64-bit hash of a byte buffer.
68
*
69
* Call clear () between calls to GetHash64() to reset the
70
* internal state and hash each buffer separately.
71
*
72
* If you don't call clear() between calls to GetHash64,
73
* you can hash successive buffers. The final return value
74
* will be the cumulative hash across all calls.
75
*
76
* \param [in] buffer pointer to the beginning of the buffer
77
* \param [in] size length of the buffer, in bytes
78
* \return 64-bit hash of the buffer
79
*/
80
uint64_t
GetHash64
(
const
char
* buffer,
const
std::size_t size)
override
;
81
/**
82
* Restore initial state
83
*/
84
void
clear
()
override
;
85
86
private
:
87
/**
88
* Seed value
89
*
90
* This has to be a constant for all MPI ranks to generate
91
* the same hash from the same string.
92
*/
93
static
constexpr
auto
SEED
{0x8BADF00D};
// Ate bad food
94
95
/**
96
* Cache last hash value, and total bytes hashed (needed to finalize),
97
* for incremental hashing
98
*/
99
/**@{*/
100
uint32_t
m_hash32
;
101
std::size_t
m_size32
;
102
/**@}*/
103
104
/** murmur3 produces 128-bit hash and state; we use just the first 64-bits. */
105
/**@{*/
106
uint64_t
m_hash64
[2];
107
std::size_t
m_size64
;
108
/**@}*/
109
110
};
// class Murmur3
111
112
}
// namespace Function
113
114
}
// namespace Hash
115
116
}
// namespace ns3
117
118
#endif
/* HASH_MURMUR3_H */
ns3::Hash::Function::Murmur3
Murmur3 hash function implementation.
Definition
hash-murmur3.h:45
ns3::Hash::Function::Murmur3::clear
void clear() override
Restore initial state.
Definition
hash-murmur3.cc:559
ns3::Hash::Function::Murmur3::Murmur3
Murmur3()
Constructor, clears internal state.
Definition
hash-murmur3.cc:512
ns3::Hash::Function::Murmur3::m_size32
std::size_t m_size32
Cache last hash value, and total bytes hashed (needed to finalize), for incremental hashing.
Definition
hash-murmur3.h:101
ns3::Hash::Function::Murmur3::m_hash64
uint64_t m_hash64[2]
murmur3 produces 128-bit hash and state; we use just the first 64-bits.
Definition
hash-murmur3.h:106
ns3::Hash::Function::Murmur3::GetHash32
uint32_t GetHash32(const char *buffer, const std::size_t size) override
Compute 32-bit hash of a byte buffer.
Definition
hash-murmur3.cc:518
ns3::Hash::Function::Murmur3::m_hash32
uint32_t m_hash32
Cache last hash value, and total bytes hashed (needed to finalize), for incremental hashing.
Definition
hash-murmur3.h:100
ns3::Hash::Function::Murmur3::SEED
static constexpr auto SEED
Seed value.
Definition
hash-murmur3.h:93
ns3::Hash::Function::Murmur3::GetHash64
uint64_t GetHash64(const char *buffer, const std::size_t size) override
Compute 64-bit hash of a byte buffer.
Definition
hash-murmur3.cc:531
ns3::Hash::Function::Murmur3::m_size64
std::size_t m_size64
murmur3 produces 128-bit hash and state; we use just the first 64-bits.
Definition
hash-murmur3.h:107
ns3::Hash::Implementation
Hash function implementation base class.
Definition
hash-function.h:39
uint32_t
hash-function.h
ns3::Hash::Implementation, ns3::Hash::Function::Hash32 and ns3::Hash::Function::Hash64 declarations.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
model
hash-murmur3.h
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0