#ifndef CORE_HPPASH_CODE_HPP #define CORE_HPPASH_CODE_HPP #include #include "utils/Types.hpp" namespace Core { template inline u32 hashCode(const H& key) { return key.hashCode(); } template inline u32 hashNumber(T t) { static_assert(sizeof(t) <= 8); if constexpr(sizeof(t) <= 4) { return static_cast(t); } return static_cast(static_cast(t) ^ (static_cast(t) >> 32)); } inline u32 hashCode(char key) { return hashNumber(key); } inline u32 hashCode(signed char key) { return hashNumber(key); } inline u32 hashCode(signed short key) { return hashNumber(key); } inline u32 hashCode(signed int key) { return hashNumber(key); } inline u32 hashCode(signed long key) { return hashNumber(key); } inline u32 hashCode(signed long long key) { return hashNumber(key); } inline u32 hashCode(unsigned char key) { return hashNumber(key); } inline u32 hashCode(unsigned short key) { return hashNumber(key); } inline u32 hashCode(unsigned int key) { return hashNumber(key); } inline u32 hashCode(unsigned long key) { return hashNumber(key); } inline u32 hashCode(unsigned long long key) { return hashNumber(key); } template inline consteval T emptyValue() { if constexpr(Core::IsSame) { return CHAR_MAX; } else if constexpr(Core::IsSame) { return SCHAR_MAX; } else if constexpr(Core::IsSame) { return SHRT_MAX; } else if constexpr(Core::IsSame) { return INT_MAX; } else if constexpr(Core::IsSame) { return LONG_MAX; } else if constexpr(Core::IsSame) { return LLONG_MAX; } else if constexpr(Core::IsSame) { return UCHAR_MAX; } else if constexpr(Core::IsSame) { return USHRT_MAX; } else if constexpr(Core::IsSame) { return UINT_MAX; } else if constexpr(Core::IsSame) { return ULONG_MAX; } else if constexpr(Core::IsSame) { return ULLONG_MAX; } else { return T::emptyValue(); } } } #endif