Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
fnv_1.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2014 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
******************************************************************************/
30
31
#ifndef ETL_FNV_1_INCLUDED
32
#define ETL_FNV_1_INCLUDED
33
34
#include "
platform.h
"
35
#include "
frame_check_sequence.h
"
36
#include "
ihash.h
"
37
#include "
type_traits.h
"
38
39
#include <stdint.h>
40
41
#if defined(ETL_COMPILER_KEIL)
42
#pragma diag_suppress 1300
43
#endif
44
47
48
namespace
etl
49
{
50
#if ETL_USING_64BIT_TYPES
51
//***************************************************************************
54
//***************************************************************************
55
struct
fnv_1_policy_64
56
{
57
typedef
uint64_t value_type;
58
59
uint64_t initial()
const
60
{
61
return
OFFSET_BASIS;
62
}
63
64
uint64_t add(uint64_t hash, uint8_t value)
const
65
{
66
hash *= PRIME;
67
hash ^= value;
68
return
hash;
69
}
70
71
uint64_t
final
(uint64_t hash)
const
72
{
73
return
hash;
74
}
75
76
static
ETL_CONSTANT uint64_t OFFSET_BASIS = 0xCBF29CE484222325ull;
77
static
ETL_CONSTANT uint64_t PRIME = 0x00000100000001b3ull;
78
};
79
80
//***************************************************************************
83
//***************************************************************************
84
class
fnv_1_64
:
public
etl::frame_check_sequence
<fnv_1_policy_64>
85
{
86
public
:
87
88
//*************************************************************************
90
//*************************************************************************
91
fnv_1_64
()
92
{
93
this->
reset
();
94
}
95
96
//*************************************************************************
100
//*************************************************************************
101
template
<
typename
TIterator>
102
fnv_1_64
(TIterator
begin
,
const
TIterator
end
)
103
{
104
this->
reset
();
105
this->
add
(begin,
end
);
106
}
107
};
108
109
//***************************************************************************
112
//***************************************************************************
113
struct
fnv_1a_policy_64
114
{
115
typedef
uint64_t value_type;
116
117
uint64_t initial()
const
118
{
119
return
OFFSET_BASIS;
120
}
121
122
uint64_t add(uint64_t hash, uint8_t value)
const
123
{
124
hash ^= value;
125
hash *= PRIME;
126
return
hash;
127
}
128
129
uint64_t
final
(uint64_t hash)
const
130
{
131
return
hash;
132
}
133
134
static
ETL_CONSTANT uint64_t OFFSET_BASIS = 0xCBF29CE484222325ull;
135
static
ETL_CONSTANT uint64_t PRIME = 0x00000100000001b3ull;
136
};
137
138
//***************************************************************************
141
//***************************************************************************
142
class
fnv_1a_64
:
public
etl::frame_check_sequence
<fnv_1a_policy_64>
143
{
144
public
:
145
146
//*************************************************************************
148
//*************************************************************************
149
fnv_1a_64
()
150
{
151
this->
reset
();
152
}
153
154
//*************************************************************************
158
//*************************************************************************
159
template
<
typename
TIterator>
160
fnv_1a_64
(TIterator
begin
,
const
TIterator
end
)
161
{
162
this->
reset
();
163
this->
add
(begin,
end
);
164
}
165
};
166
#endif
167
168
//***************************************************************************
171
//***************************************************************************
172
struct
fnv_1_policy_32
173
{
174
typedef
uint32_t value_type;
175
176
uint32_t initial()
const
177
{
178
return
OFFSET_BASIS;
179
}
180
181
uint32_t add(uint32_t hash, uint8_t value)
const
182
{
183
hash *= PRIME;
184
hash ^= value;
185
return
hash;
186
}
187
188
uint32_t
final
(uint32_t hash)
const
189
{
190
return
hash;
191
}
192
193
static
ETL_CONSTANT uint32_t OFFSET_BASIS = 0x811C9DC5UL;
194
static
ETL_CONSTANT uint32_t PRIME = 0x01000193UL;
195
};
196
197
//***************************************************************************
200
//***************************************************************************
201
class
fnv_1_32
:
public
etl::frame_check_sequence
<fnv_1_policy_32>
202
{
203
public
:
204
205
//*************************************************************************
207
//*************************************************************************
208
fnv_1_32
()
209
{
210
this->
reset
();
211
}
212
213
//*************************************************************************
217
//*************************************************************************
218
template
<
typename
TIterator>
219
fnv_1_32
(TIterator
begin
,
const
TIterator
end
)
220
{
221
this->
reset
();
222
this->
add
(begin,
end
);
223
}
224
};
225
226
//***************************************************************************
229
//***************************************************************************
230
struct
fnv_1a_policy_32
231
{
232
typedef
uint32_t value_type;
233
234
uint32_t initial()
const
235
{
236
return
OFFSET_BASIS;
237
}
238
239
uint32_t add(uint32_t hash, uint8_t value)
const
240
{
241
hash ^= value;
242
hash *= PRIME;
243
return
hash;
244
}
245
246
uint32_t
final
(uint32_t hash)
const
247
{
248
return
hash;
249
}
250
251
static
ETL_CONSTANT uint32_t OFFSET_BASIS = 0x811C9DC5UL;
252
static
ETL_CONSTANT uint32_t PRIME = 0x01000193UL;
253
};
254
255
//***************************************************************************
258
//***************************************************************************
259
class
fnv_1a_32
:
public
etl::frame_check_sequence
<fnv_1a_policy_32>
260
{
261
public
:
262
263
//*************************************************************************
265
//*************************************************************************
266
fnv_1a_32
()
267
{
268
this->
reset
();
269
}
270
271
//*************************************************************************
275
//*************************************************************************
276
template
<
typename
TIterator>
277
fnv_1a_32
(TIterator
begin
,
const
TIterator
end
)
278
{
279
this->
reset
();
280
this->
add
(begin,
end
);
281
}
282
};
283
}
// namespace etl
284
285
#endif
etl::fnv_1_32::fnv_1_32
fnv_1_32(TIterator begin, const TIterator end)
Definition
fnv_1.h:219
etl::fnv_1_32::fnv_1_32
fnv_1_32()
Default constructor.
Definition
fnv_1.h:208
etl::fnv_1_64::fnv_1_64
fnv_1_64(TIterator begin, const TIterator end)
Definition
fnv_1.h:102
etl::fnv_1_64::fnv_1_64
fnv_1_64()
Default constructor.
Definition
fnv_1.h:91
etl::fnv_1a_32::fnv_1a_32
fnv_1a_32()
Default constructor.
Definition
fnv_1.h:266
etl::fnv_1a_32::fnv_1a_32
fnv_1a_32(TIterator begin, const TIterator end)
Definition
fnv_1.h:277
etl::fnv_1a_64::fnv_1a_64
fnv_1a_64()
Default constructor.
Definition
fnv_1.h:149
etl::fnv_1a_64::fnv_1a_64
fnv_1a_64(TIterator begin, const TIterator end)
Definition
fnv_1.h:160
frame_check_sequence.h
etl::frame_check_sequence< fnv_1_policy_64 >::add
ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
Definition
frame_check_sequence.h:145
etl::frame_check_sequence< fnv_1_policy_64 >::reset
ETL_CONSTEXPR14 void reset()
Definition
frame_check_sequence.h:134
etl::frame_check_sequence
Definition
frame_check_sequence.h:98
ihash.h
etl
Definition
absolute.h:40
etl::end
TContainer::iterator end(TContainer &container)
Definition
iterator.h:1166
etl::begin
TContainer::iterator begin(TContainer &container)
Definition
iterator.h:1136
platform.h
etl::fnv_1_policy_32
Definition
fnv_1.h:173
etl::fnv_1_policy_64
Definition
fnv_1.h:56
etl::fnv_1a_policy_32
Definition
fnv_1.h:231
etl::fnv_1a_policy_64
Definition
fnv_1.h:114
type_traits.h
include
etl
fnv_1.h
Generated on
for Embedded Template Library by
1.17.0