35 template <
typename DERIVED>
61 template <
typename TYPE>
76 static u_integer hashFuncImpl(
const T& t)
noexcept;
114 template <
typename T,
typename... Rest>
125 template <
typename T>
128 template <
typename T>
138 template<std::
integral T>
147 template <
typename T>
205 template <
typename DERIVED>
221 virtual
bool equals(const DERIVED& other) const noexcept;
244 std::size_t operator()(
const T& t)
const noexcept;
247template<
typename TYPE>
253template<
typename TYPE>
256 if constexpr (std::is_trivially_copyable_v<T>) {
257 byte buffer[
sizeof(T)];
258 std::memcpy(buffer, &t,
sizeof(T));
259 return fnv1a(buffer,
sizeof(T));
261 return static_cast<u_integer>(
reinterpret_cast<uintptr_t
>(&t));
265template<
typename TYPE>
270 hash *= FNV_32_PRIME;
275template<
typename TYPE>
276template<
typename T,
typename... Rest>
278 hashCombine(seed, value);
279 (hashCombine(seed, rest), ...);
282template<
typename TYPE>
285 return hashFuncImpl(t);
288template <
typename TYPE>
294template<
typename TYPE>
299template<
typename TYPE>
300template<std::
integral T>
305template<
typename TYPE>
308 return static_cast<u_integer>(
reinterpret_cast<uintptr_t
>(t));
311template<
typename TYPE>
316template<
typename TYPE>
318 if (str ==
nullptr)
return 0;
319 return fnv1a(
reinterpret_cast<const byte*
>(str), std::strlen(str));
322template<
typename TYPE>
324 return fnv1a(
reinterpret_cast<const byte*
>(str.data()), str.size());
327template<
typename TYPE>
332template <
typename DERIVED>
337template<
typename DERIVED>
339 return static_cast<const DERIVED&
>(*this) == other;
342template <
typename DERIVED>
347std::size_t std::hash<T>::operator()(
const T &t)
const noexcept {
348 return static_cast<std::size_t
>(t.toHash());
Generic hash function object supporting multiple types.
Definition hash.h:62
static u_integer hashFunc(const T &t) noexcept
Default hash function fallback.
static void hashCombine(u_integer &seed, const T &value, const Rest &... rest) noexcept
Combines multiple hash values into one.
Definition hash.h:277
static u_integer hashFunc(const std::nullptr_t &null) noexcept
Hash function for nullptr.
Definition hash.h:295
static u_integer hashFunc(T *const &t) noexcept
Hash function for pointers.
static void hashCombine(u_integer &seed, const T &value) noexcept
Combines a hash value with another value's hash.
Definition hash.h:249
u_integer operator()(const TYPE &t) const noexcept
Hash function object call operator.
Definition hash.h:328
static u_integer hashFunc(const char &t) noexcept
Hash function for single character.
Definition hash.h:312
static u_integer hashFunc(const char *str) noexcept
Hash function for C-style strings.
Definition hash.h:317
static u_integer hashFunc(const std::string &str) noexcept
Hash function for std::string.
Definition hash.h:323
static constexpr u_integer FNV_OFFSET_BASIS
FNV-1a initial offset value (0x811C9DC5)
Definition hash.h:83
static constexpr u_integer FNV_32_PRIME
FNV-1a prime multiplier (0x01000193)
Definition hash.h:86
static u_integer fnv1a(const byte *data, u_integer size) noexcept
FNV-1a hash implementation for raw byte data.
Definition hash.h:266
Forward declaration of hashable interface template.
Definition hash.h:206
virtual bool equals(const DERIVED &other) const noexcept
Compares two objects for equality.
Definition hash.h:338
virtual ~hashable()=0
Virtual destructor.
virtual u_integer toHash() const noexcept
Computes the hash of the object.
Definition hash.h:333
Checks derivation or type identity using std::derived_from.
Definition types.h:393
Platform-independent type definitions and compiler/platform detection.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
Main namespace for the project Original.
Definition algorithms.h:21
Core type system foundations and concept definitions.