tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
fnv1a.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2025 Tobias Hienzsch
3#ifndef TETL_FUNCTIONAL_FNV1A_HPP
4#define TETL_FUNCTIONAL_FNV1A_HPP
5
6#include <etl/_config/all.hpp>
7
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_cstdint/uint_t.hpp>
10
11namespace etl {
12
13template <typename UInt, UInt Prime, UInt Offset>
14struct fnv1a {
15 using result_type = UInt;
16
17 fnv1a() = default;
18
19 auto operator()(void const* data, etl::size_t len) noexcept -> void
20 {
21 auto const* p = static_cast<etl::uint8_t const*>(data);
22 TETL_NO_UNROLL while ((len--) != 0U)
23 {
24 _h ^= static_cast<UInt>(*p++);
25 _h *= Prime;
26 }
27 }
28
29 explicit operator result_type() const noexcept
30 {
31 return _h;
32 }
33
34private:
35 result_type _h{Offset};
36};
37
38using fnv1a32 = fnv1a<etl::uint32_t, 0x01000193, 0x811c9dc5>;
39using fnv1a64 = fnv1a<etl::uint64_t, 0x00000100000001b3, 0xcbf29ce484222325>;
40
41} // namespace etl
42
43#endif // TETL_FUNCTIONAL_FNV1A_HPP
Definition adjacent_find.hpp:9
Definition fnv1a.hpp:14
fnv1a()=default
operator result_type() const noexcept
Definition fnv1a.hpp:29
auto operator()(void const *data, etl::size_t len) noexcept -> void
Definition fnv1a.hpp:19