FE 0.13.1
Header-only C++ frontend library
Loading...
Searching...
No Matches
hash.h File Reference
#include <concepts>
#include <cstddef>
#include <cstdint>
Include dependency graph for hash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  fe

Functions

Bit Mixers

These finalizers scramble a single word.

They are bijective, i.e., they don't introduce any collisions on their own - they merely spread the input bits.

constexpr uint32_t fe::murmur3 (uint32_t h) noexcept
 MurmurHash3's 32-bit finalizer fmix32.
constexpr uint64_t fe::splitmix64 (uint64_t h) noexcept
 SplitMix64's 64-bit finalizer.
constexpr size_t fe::hash (size_t h) noexcept
 Mixes h with murmur3 or splitmix64 - whichever matches sizeof(size_t).

FNV-1 Hash

See Wikipedia.

Use hash_begin to seed a hash chain and hash_combine to fold in one value after another:

auto h = fe::hash_begin(x);
for (auto elem : elems) h = fe::hash_combine(h, elem);
constexpr size_t hash_begin() noexcept
Seeds a hash chain with the FNV-1 offset basis.
Definition hash.h:64
constexpr size_t hash_combine(size_t seed, T v) noexcept
Mixes v into seed word-wise, reusing the FNV-1 prime as multiplier.
Definition hash.h:68
Note
These hashes are not stable: they differ between 32- and 64-bit builds and may change between fe releases. Never serialize them and never rely on the iteration order they induce.
constexpr size_t fe::fnv1_offset = sizeof(size_t) == 4 ? size_t(UINT32_C(2166136261)) : size_t(UINT64_C(14695981039346656037))
 FNV-1 magic numbers for sizeof(size_t).
constexpr size_t fe::fnv1_prime = sizeof(size_t) == 4 ? size_t(UINT32_C( 16777619)) : size_t(UINT64_C( 1099511628211))
constexpr size_t fe::hash_begin () noexcept
 Seeds a hash chain with the FNV-1 offset basis.
template<std::integral T>
constexpr size_t fe::hash_combine (size_t seed, T v) noexcept
 Mixes v into seed word-wise, reusing the FNV-1 prime as multiplier.
template<std::integral T>
constexpr size_t fe::hash_begin (T v) noexcept
 Shorthand for hash_combine(hash_begin(), v).