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