37 template <
typename TYPE>
44 template <
typename DERIVED>
55 template <
typename DERIVED>
57 requires(
const DERIVED& t,
const DERIVED& other) {
58 { t.toHash() } -> std::same_as<u_integer>;
59 { t.equals(other) } -> std::same_as<bool>;
79 template <
typename TYPE>
102 template <
typename T>
103 static u_integer hashFuncImpl(
const T& t)
noexcept;
107 friend class hashable;
132 template <
typename T>
141 template <isHashable T>
150 template<std::
integral T>
159 template <
typename T>
215 template <
typename DERIVED>
231 virtual
bool equals(const DERIVED& other) const noexcept;
238template<typename TYPE>
241 if constexpr (std::is_trivially_copyable_v<T>) {
242 byte buffer[
sizeof(T)];
243 std::memcpy(buffer, &t,
sizeof(T));
244 return fnv1a(buffer,
sizeof(T));
246 return static_cast<u_integer>(
reinterpret_cast<uintptr_t
>(&t));
250template<
typename TYPE>
260template<
typename TYPE>
263 return hashFuncImpl(t);
266template<
typename TYPE>
267template<original::isHashable T>
272template<
typename TYPE>
277template<
typename TYPE>
278template<std::
integral T>
283template<
typename TYPE>
286 return static_cast<u_integer>(
reinterpret_cast<uintptr_t
>(t));
289template<
typename TYPE>
294template<
typename TYPE>
296 if (str ==
nullptr)
return 0;
297 return fnv1a(
reinterpret_cast<const byte*
>(str), std::strlen(str));
300template<
typename TYPE>
302 return fnv1a(
reinterpret_cast<const byte*
>(str.data()), str.size());
305template<
typename TYPE>
310template <
typename DERIVED>
312 return hash<DERIVED>::hashFuncImpl(
static_cast<const DERIVED&
>(*
this));
315template<
typename DERIVED>
317 return static_cast<const DERIVED&
>(*this) == other;
320template <
typename DERIVED>
Forward declaration of hash class template.
Definition hash.h:80
static u_integer hashFunc(const T &t) noexcept
Default hash function fallback.
static u_integer hashFunc(const std::nullptr_t &null) noexcept
Hash function for nullptr.
Definition hash.h:273
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:306
static u_integer hashFunc(const char &t) noexcept
Hash function for single character.
Definition hash.h:290
static u_integer hashFunc(const char *str) noexcept
Hash function for C-style strings.
Definition hash.h:295
static u_integer hashFunc(const std::string &str) noexcept
Hash function for std::string.
Definition hash.h:301
static constexpr u_integer FNV_OFFSET_BASIS
FNV-1a initial offset value.
Definition hash.h:110
static constexpr u_integer FNV_32_PRIME
FNV-1a prime multiplier.
Definition hash.h:113
static u_integer fnv1a(const byte *data, u_integer size) noexcept
FNV-1a hash implementation for raw byte data.
Definition hash.h:251
Forward declaration of hashable interface template.
Definition hash.h:216
virtual bool equals(const DERIVED &other) const noexcept
Definition hash.h:316
virtual ~hashable()=0
Virtual destructor.
virtual u_integer toHash() const noexcept
Computes the hash of the object.
Definition hash.h:311
Concept checking for hashable types.
Definition hash.h:56
Platform-independent integer and floating-point type definitions.
Main namespace for the project Original.
Definition algorithms.h:21
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:43