35 template <
typename TYPE>
42 template <
typename DERIVED>
61 template <
typename DERIVED>
63 requires(
const DERIVED& t,
const DERIVED& other) {
64 { t.toHash() } -> std::same_as<u_integer>;
65 { t.equals(other) } -> std::same_as<bool>;
91 template <
typename TYPE>
100 static inline void hashCombine(
u_integer& seed,
const T& value)
noexcept;
113 template <
typename T>
114 static u_integer hashFuncImpl(
const T& t)
noexcept;
143 template <
typename T,
typename... Rest>
154 template <
typename T>
163 template <isHashable T>
172 template<std::
integral T>
181 template <
typename T>
239 template <
typename DERIVED>
255 virtual
bool equals(const DERIVED& other) const noexcept;
278 std::size_t operator()(
const T& t)
const noexcept;
281template<
typename TYPE>
287template<
typename TYPE>
290 if constexpr (std::is_trivially_copyable_v<T>) {
291 byte buffer[
sizeof(T)];
292 std::memcpy(buffer, &t,
sizeof(T));
293 return fnv1a(buffer,
sizeof(T));
295 return static_cast<u_integer>(
reinterpret_cast<uintptr_t
>(&t));
299template<
typename TYPE>
304 hash *= FNV_32_PRIME;
309template<
typename TYPE>
310template<
typename T,
typename... Rest>
312 hashCombine(seed, value);
313 (hashCombine(seed, rest), ...);
316template<
typename TYPE>
319 return hashFuncImpl(t);
322template<
typename TYPE>
323template<original::isHashable T>
328template<
typename TYPE>
333template<
typename TYPE>
334template<std::
integral T>
339template<
typename TYPE>
342 return static_cast<u_integer>(
reinterpret_cast<uintptr_t
>(t));
345template<
typename TYPE>
350template<
typename TYPE>
352 if (str ==
nullptr)
return 0;
353 return fnv1a(
reinterpret_cast<const byte*
>(str), std::strlen(str));
356template<
typename TYPE>
358 return fnv1a(
reinterpret_cast<const byte*
>(str.data()), str.size());
361template<
typename TYPE>
366template <
typename DERIVED>
371template<
typename DERIVED>
373 return static_cast<const DERIVED&
>(*this) == other;
376template <
typename DERIVED>
381std::size_t std::hash<T>::operator()(
const T &t)
const noexcept {
382 return static_cast<std::size_t
>(t.toHash());
Forward declaration of hash class template.
Definition hash.h:92
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:311
static u_integer hashFunc(const std::nullptr_t &null) noexcept
Hash function for nullptr.
Definition hash.h:329
static u_integer hashFunc(T *const &t) noexcept
Hash function for pointers.
u_integer operator()(const TYPE &t) const noexcept
Hash function object call operator.
Definition hash.h:362
static u_integer hashFunc(const char &t) noexcept
Hash function for single character.
Definition hash.h:346
static u_integer hashFunc(const char *str) noexcept
Hash function for C-style strings.
Definition hash.h:351
static u_integer hashFunc(const std::string &str) noexcept
Hash function for std::string.
Definition hash.h:357
static constexpr u_integer FNV_OFFSET_BASIS
FNV-1a initial offset value (0x811C9DC5)
Definition hash.h:121
static constexpr u_integer FNV_32_PRIME
FNV-1a prime multiplier (0x01000193)
Definition hash.h:124
static u_integer fnv1a(const byte *data, u_integer size) noexcept
FNV-1a hash implementation for raw byte data.
Definition hash.h:300
Forward declaration of hashable interface template.
Definition hash.h:240
virtual bool equals(const DERIVED &other) const noexcept
Compares two objects for equality.
Definition hash.h:372
virtual ~hashable()=0
Virtual destructor.
virtual u_integer toHash() const noexcept
Computes the hash of the object.
Definition hash.h:367
Concept checking for types that can be hashed.
Definition hash.h:62
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