Antkeeper  0.0.1
Namespaces | Functions
hash Namespace Reference

Hash functions. More...

Namespaces

 literals
 User-defined literals for compile-time string hashing.
 
 types
 Distinct hash value types for different hash algorithms.
 

Functions

template<std::unsigned_integral HashT, std::integral DataT>
constexpr HashT fnv1a (std::span< const DataT > data, HashT offset, HashT prime) noexcept
 FNV-1a hash function. More...
 
template<std::integral DataT>
constexpr std::uint32_t fnv1a32 (std::span< const DataT > data) noexcept
 32-bit FNV-1a hash function. More...
 
template<std::integral DataT>
constexpr std::uint64_t fnv1a64 (std::span< const DataT > data) noexcept
 64-bit FNV-1a hash function. More...
 

Detailed Description

Hash functions.

Function Documentation

◆ fnv1a()

template<std::unsigned_integral HashT, std::integral DataT>
constexpr HashT hash::fnv1a ( std::span< const DataT >  data,
HashT  offset,
HashT  prime 
)
constexprnoexcept

FNV-1a hash function.

Template Parameters
HashTUnsigned integral hash type.
DataTData element type.
Parameters
dataArray of data to hash.
offsetFNV offset basis value.
primeFNV prime value.
Returns
Hash value.
See also
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function

@TODO reinterpret_cast is not supported in consteval. C++23 has if consteval which can selectively enable reinterpret_cast at runtime, and extract bytes manually at compile-time.

Definition at line 46 of file fnv1a.hpp.

◆ fnv1a32()

template<std::integral DataT>
constexpr std::uint32_t hash::fnv1a32 ( std::span< const DataT >  data)
constexprnoexcept

32-bit FNV-1a hash function.

Template Parameters
DataTData element type.
Parameters
dataArray of data to hash.
Returns
32-bit FNV-1a hash value.

Definition at line 79 of file fnv1a.hpp.

◆ fnv1a64()

template<std::integral DataT>
constexpr std::uint64_t hash::fnv1a64 ( std::span< const DataT >  data)
constexprnoexcept

64-bit FNV-1a hash function.

Template Parameters
DataTData element type.
Parameters
dataArray of data to hash.
Returns
64-bit FNV-1a hash value.

Definition at line 100 of file fnv1a.hpp.