header_utils
Loading...
Searching...
No Matches
Hashes

Hashing functions, mostly constexpr when possible. More...

Namespaces

namespace  ghassanpl::integer
 Hash functions that only work on integers.

Functions

template<bytelike_range RANGE>
constexpr uint32_t ghassanpl::crc32 (RANGE &&bytes)
 Calculates a CRC32 for a range of bytelikes.
template<bytelike... BYTES>
constexpr uint32_t ghassanpl::crc32 (BYTES... bytes)
 Calculates a CRC32 for a variadic number of bytelikes.
template<bytelike_range RANGE>
constexpr uint64_t ghassanpl::crc64 (RANGE &&bytes)
 Calculates a CRC4 for a range of bytelikes.
template<bytelike... BYTES>
constexpr uint64_t ghassanpl::crc64 (BYTES... bytes)
 Calculates a CRC4 for a variadic number of bytelikes.
template<bytelike_range RANGE>
constexpr uint64_t ghassanpl::fnv64 (RANGE &&bytes)
 Calculates a FNV Hash for a range of bytes.
template<bytelike... BYTES>
constexpr uint64_t ghassanpl::fnv64 (BYTES... bytes)
 Calculates a FNV Hash for a variadic number of bytes.
constexpr void ghassanpl::fold_in_hash64 (uint64_t &hash1, uint64_t hash2) noexcept
 Combines an existing hash with a new hash value.
template<typename T, typename HASHER = std::hash<std::remove_cvref_t<T>>>
constexpr void ghassanpl::hash64_combine_to (uint64_t &seed, T &&v, HASHER &&hasher=HASHER{})
 Combines an existing hash value (seed) with the hash of value v.
template<template< typename > typename HASHER = std::hash, typename FIRST, typename... T>
constexpr uint64_t ghassanpl::hash64 (FIRST const &first, T &&... values)
 Performs a hash of multiple values.
template<typename It, typename HASHER = std::hash<std::iter_value_t<It>>>
constexpr void ghassanpl::fold_in_hash64_range (uint64_t &seed, It first, It last, HASHER const &hasher={})
 Combines an existing hash value (seed) with the hash of a range of values.
template<typename It, typename HASHER = std::hash<std::iter_value_t<It>>>
constexpr uint64_t ghassanpl::hash64_range (It first, It last, HASHER &&hasher={})
 Hashes a range of values.
template<std::ranges::range T, typename HASHER = std::hash<std::ranges::range_value_t<T>>>
constexpr uint64_t ghassanpl::hash64_range (T range, HASHER &&hasher={})
 Hashes a range of values.

Variables

static constexpr uint32_t ghassanpl::crc32_table [256]
static constexpr uint64_t ghassanpl::crc64_table [256]

consteval Hash Functions

template<typename T>
consteval uint64_t ghassanpl::ce_hash64 (T val) noexcept
template<bytelike T>
consteval uint64_t ghassanpl::ce_hash64 (std::basic_string_view< T > const &val) noexcept
template<typename FIRST, typename... T>
consteval uint64_t ghassanpl::ce_hash64 (FIRST const &first, T const &... values)
template<typename TUPLE_TYPE, uint64_t... Is>
consteval void ghassanpl::ce_hash64_tuple_elements (uint64_t &hash, TUPLE_TYPE const &t, std::index_sequence< Is... >)
template<typename... T>
consteval uint64_t ghassanpl::ce_hash64 (std::tuple< T... > const &tupl) noexcept

Detailed Description

Hashing functions, mostly constexpr when possible.

Function Documentation

◆ ce_hash64() [1/4]

template<typename FIRST, typename... T>
uint64_t ghassanpl::ce_hash64 ( FIRST const & first,
T const &... values )
nodiscardconsteval

Definition at line 349 of file hashes.h.

◆ ce_hash64() [2/4]

template<bytelike T>
uint64_t ghassanpl::ce_hash64 ( std::basic_string_view< T > const & val)
nodiscardconstevalnoexcept

Definition at line 345 of file hashes.h.

◆ ce_hash64() [3/4]

template<typename... T>
uint64_t ghassanpl::ce_hash64 ( std::tuple< T... > const & tupl)
nodiscardconstevalnoexcept

Definition at line 363 of file hashes.h.

◆ ce_hash64() [4/4]

template<typename T>
uint64_t ghassanpl::ce_hash64 ( T val)
nodiscardconstevalnoexcept

Definition at line 332 of file hashes.h.

◆ ce_hash64_tuple_elements()

template<typename TUPLE_TYPE, uint64_t... Is>
void ghassanpl::ce_hash64_tuple_elements ( uint64_t & hash,
TUPLE_TYPE const & t,
std::index_sequence< Is... >  )
consteval

Definition at line 357 of file hashes.h.

◆ crc32() [1/2]

template<bytelike... BYTES>
uint32_t ghassanpl::crc32 ( BYTES... bytes)
nodiscardconstexpr

Calculates a CRC32 for a variadic number of bytelikes.

constexpr!

Definition at line 83 of file hashes.h.

◆ crc32() [2/2]

template<bytelike_range RANGE>
uint32_t ghassanpl::crc32 ( RANGE && bytes)
nodiscardconstexpr

Calculates a CRC32 for a range of bytelikes.

constexpr!

Definition at line 70 of file hashes.h.

◆ crc64() [1/2]

template<bytelike... BYTES>
uint64_t ghassanpl::crc64 ( BYTES... bytes)
nodiscardconstexpr

Calculates a CRC4 for a variadic number of bytelikes.

Definition at line 146 of file hashes.h.

◆ crc64() [2/2]

template<bytelike_range RANGE>
uint64_t ghassanpl::crc64 ( RANGE && bytes)
nodiscardconstexpr

Calculates a CRC4 for a range of bytelikes.

Definition at line 136 of file hashes.h.

◆ fnv64() [1/2]

template<bytelike... BYTES>
uint64_t ghassanpl::fnv64 ( BYTES... bytes)
nodiscardconstexpr

Calculates a FNV Hash for a variadic number of bytes.

Definition at line 181 of file hashes.h.

◆ fnv64() [2/2]

template<bytelike_range RANGE>
uint64_t ghassanpl::fnv64 ( RANGE && bytes)
nodiscardconstexpr

Calculates a FNV Hash for a range of bytes.

Definition at line 171 of file hashes.h.

◆ fold_in_hash64()

void ghassanpl::fold_in_hash64 ( uint64_t & hash1,
uint64_t hash2 )
constexprnoexcept

Combines an existing hash with a new hash value.

Definition at line 251 of file hashes.h.

◆ fold_in_hash64_range()

template<typename It, typename HASHER = std::hash<std::iter_value_t<It>>>
void ghassanpl::fold_in_hash64_range ( uint64_t & seed,
It first,
It last,
HASHER const & hasher = {} )
constexpr

Combines an existing hash value (seed) with the hash of a range of values.

Definition at line 297 of file hashes.h.

◆ hash64()

template<template< typename > typename HASHER = std::hash, typename FIRST, typename... T>
uint64_t ghassanpl::hash64 ( FIRST const & first,
T &&... values )
nodiscardconstexpr

Performs a hash of multiple values.

Definition at line 274 of file hashes.h.

◆ hash64_combine_to()

template<typename T, typename HASHER = std::hash<std::remove_cvref_t<T>>>
void ghassanpl::hash64_combine_to ( uint64_t & seed,
T && v,
HASHER && hasher = HASHER{} )
constexpr

Combines an existing hash value (seed) with the hash of value v.

Definition at line 265 of file hashes.h.

◆ hash64_range() [1/2]

template<typename It, typename HASHER = std::hash<std::iter_value_t<It>>>
uint64_t ghassanpl::hash64_range ( It first,
It last,
HASHER && hasher = {} )
nodiscardconstexpr

Hashes a range of values.

Definition at line 306 of file hashes.h.

◆ hash64_range() [2/2]

template<std::ranges::range T, typename HASHER = std::hash<std::ranges::range_value_t<T>>>
uint64_t ghassanpl::hash64_range ( T range,
HASHER && hasher = {} )
nodiscardconstexpr

Hashes a range of values.

Definition at line 316 of file hashes.h.

Variable Documentation

◆ crc32_table

uint32_t ghassanpl::crc32_table[256]
inlinestaticconstexpr

Definition at line 21 of file hashes.h.

◆ crc64_table

uint64_t ghassanpl::crc64_table[256]
inlinestaticconstexpr

Definition at line 99 of file hashes.h.