sdi_toolBox::common::utils::hash Namespace Reference

Lightweight hashing utilities (FNV-1a implementations). More...

## Functions

constexpr std::uint32_t | fnv1a (std::span< const std::byte > data) noexcept
| Compute the FNV-1a 32-bit hash for a span of bytes.
constexpr std::uint32_t | fnv1a (std::string_view sv) noexcept
| Compute the FNV-1a 32-bit hash for a std::string_view.
template<typename T > requires std::is_trivially_copyable_v<T>
constexpr std::uint32_t | fnv1a (const T &value) noexcept
| Compute the FNV-1a 32-bit hash for a trivially copyable POD object.
constexpr std::uint64_t | fnv1a_64 (std::span< const std::byte > data) noexcept
| Compute the FNV-1a 64-bit hash for a span of bytes.
constexpr std::uint64_t | fnv1a_64 (std::string_view sv) noexcept
| Compute the FNV-1a 64-bit hash for a std::string_view.
template<typename T > requires std::is_trivially_copyable_v<T>
constexpr std::uint64_t | fnv1a_64 (const T &value) noexcept
| Compute the FNV-1a 64-bit hash for a trivially copyable POD object.

## Detailed Description

Lightweight hashing utilities (FNV-1a implementations).

Provides constexpr, header-only implementations of the FNV-1a hashing algorithms (32-bit and 64-bit) with overloads that accept:

- std::span<const std::byte>
- std::string_view
- trivially-copyable POD objects

These utilities are intended for fast, deterministic hashing of byte sequences and simple value-based hashing of POD types. Implementations are usable in constexpr contexts for string literals and other compile-time scenarios.

Note
  Use the POD overloads only for trivially-copyable types where hashing the raw memory representation is intended.

See also
  fnv1a(), fnv1a_64()

## Function Documentation

## fnv1a() [1/3]

constexpr std::uint32_t fnv1a | ( | std::span< const std::byte > | data | ) |

inlineconstexprnoexcept

Compute the FNV-1a 32-bit hash for a span of bytes.

Primary API: accepts a `std::span<const std::byte>` so callers can pass any contiguous buffer without copies.

Parameters

  data | Span of bytes to hash.

Returns
  std::uint32_t 32-bit FNV-1a hash.

Definition at line 95 of file hash.h.

## fnv1a() [2/3]

constexpr std::uint32_t fnv1a | ( | std::string_view | sv | ) |

inlineconstexprnoexcept

Compute the FNV-1a 32-bit hash for a std::string_view.

Convenience overload forwarding to the byte-based implementation.

Parameters

  sv | Input string view.

Returns
  std::uint32_t The 32-bit FNV-1a hash.

Definition at line 110 of file hash.h.

## fnv1a() [3/3]

template<typename T >
requires std::is_trivially_copyable_v<T>

constexpr std::uint32_t fnv1a | ( | const T & | value | ) |

inlineconstexprnoexcept

Compute the FNV-1a 32-bit hash for a trivially copyable POD object.

The object is hashed as its raw bytes (binary representation). Use only for POD/trivially-copyable types where this behaviour is intended.

Template Parameters

  T | Trivially copyable type.

Parameters

  value | Reference to the object to hash.

Returns
  std::uint32_t 32-bit FNV-1a hash.

Definition at line 118 of file hash.h.

## fnv1a_64() [1/3]

constexpr std::uint64_t fnv1a_64 | ( | std::span< const std::byte > | data | ) |

inlineconstexprnoexcept

Compute the FNV-1a 64-bit hash for a span of bytes.

Primary API: accepts a `std::span<const std::byte>` so callers can pass any contiguous buffer without copies.

Parameters

  data | Span of bytes to hash.

Returns
  std::uint64_t 64-bit FNV-1a hash.

Definition at line 124 of file hash.h.

## fnv1a_64() [2/3]

constexpr std::uint64_t fnv1a_64 | ( | std::string_view | sv | ) |

inlineconstexprnoexcept

Compute the FNV-1a 64-bit hash for a std::string_view.

Convenience overload forwarding to the byte-based implementation.

Parameters

  sv | Input string view.

Returns
  std::uint64_t The 64-bit FNV-1a hash.

Definition at line 139 of file hash.h.

## fnv1a_64() [3/3]

template<typename T >
requires std::is_trivially_copyable_v<T>

constexpr std::uint64_t fnv1a_64 | ( | const T & | value | ) |

inlineconstexprnoexcept

Compute the FNV-1a 64-bit hash for a trivially copyable POD object.

The object is hashed as its raw bytes (binary representation). Use only for POD/trivially-copyable types where this behaviour is intended.

Template Parameters

  T | Trivially copyable type.

Parameters

  value | Reference to the object to hash.

Returns
  std::uint64_t 64-bit FNV-1a hash.

Definition at line 147 of file hash.h.