#pragma once #include #include #include #include #include #include #include #include #include #include namespace types { // taken from linux constexpr uint32_t GOLDEN_RATIO_32 = 0x61C88647; // constexpr uint64_t GOLDEN_RATIO_64 = 0x61C8864680B583EBull; using hash_t = size_t; static inline constexpr hash_t _hash32(uint32_t val) { return val * GOLDEN_RATIO_32; } static inline constexpr hash_t hash32(uint32_t val, uint32_t bits) { // higher bits are more random return _hash32(val) >> (32 - bits); } template struct linux_hasher {}; template inline constexpr bool is_c_string_v = std::is_same_v, char*> || std::is_same_v, const char*>; template struct linux_hasher>> { static inline constexpr hash_t hash(T val, uint32_t bits) { return hash32(static_cast(val), bits); } }; template struct linux_hasher && !is_c_string_v>> { static inline constexpr hash_t hash(T val, uint32_t bits) { return hash32(std::bit_cast(val), bits); } }; template struct linux_hasher>> { static inline constexpr hash_t hash(const char* str, uint32_t bits) { constexpr uint32_t seed = 131; uint32_t hash = 0; while (*str) hash = hash * seed + (*str++); return hash32(hash, bits); } }; template