Skip to content

Commit cc645e1

Browse files
committed
Implement _Hash_bytes for AVR using crc ccitt from avr-libc
1 parent 1e245c1 commit cc645e1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: src/hash_bytes.cc

+19
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
// FNV is provided primarily for backward compatibility.
3434

3535
#include <bits/hash_bytes.h>
36+
#include <type_traits>
37+
38+
#ifdef __AVR__
39+
#include <util/crc16.h>
40+
#endif
3641

3742
namespace
3843
{
@@ -174,7 +179,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
174179
}
175180
return hash;
176181
}
182+
#elif __SIZEOF_SIZE_T__ == 2 && defined(__AVR__)
183+
size_t
184+
_Hash_bytes(const void* ptr, size_t len, size_t seed)
185+
{
186+
static_assert(is_same_v<uint16_t, size_t>);
187+
size_t hash = seed;
188+
const char* cptr = reinterpret_cast<const char*>(ptr);
189+
for (; len; --len)
190+
hash = _crc_ccitt_update(hash, *cptr++);
191+
return hash;
192+
}
177193

194+
size_t
195+
_Fnv_hash_bytes(const void* ptr, size_t len, size_t seed)
196+
{ return _Hash_bytes(ptr, len, seed); }
178197
#else
179198

180199
// Dummy hash implementation for unusual sizeof(size_t).

0 commit comments

Comments
 (0)