mirror of https://github.com/AxioDL/metaforce.git
Merge pull request #4 from lioncash/hash
hecl/hecl: Make Hash interface constexpr where applicable
This commit is contained in:
commit
1ea371b5cd
|
@ -409,35 +409,36 @@ protected:
|
||||||
uint64_t hash = 0;
|
uint64_t hash = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Hash() = default;
|
constexpr Hash() = default;
|
||||||
operator bool() const { return hash != 0; }
|
constexpr Hash(const Hash&) = default;
|
||||||
Hash(const void* buf, size_t len) : hash(XXH64((uint8_t*)buf, len, 0)) {}
|
constexpr Hash(Hash&&) noexcept = default;
|
||||||
Hash(std::string_view str) : hash(XXH64((uint8_t*)str.data(), str.size(), 0)) {}
|
constexpr Hash(uint64_t hashin) : hash(hashin) {}
|
||||||
Hash(std::wstring_view str) : hash(XXH64((uint8_t*)str.data(), str.size() * 2, 0)) {}
|
explicit Hash(const void* buf, size_t len) : hash(XXH64((uint8_t*)buf, len, 0)) {}
|
||||||
Hash(uint64_t hashin) : hash(hashin) {}
|
explicit Hash(std::string_view str) : hash(XXH64((uint8_t*)str.data(), str.size(), 0)) {}
|
||||||
Hash(const Hash& other) { hash = other.hash; }
|
explicit Hash(std::wstring_view str) : hash(XXH64((uint8_t*)str.data(), str.size() * 2, 0)) {}
|
||||||
uint32_t val32() const { return uint32_t(hash) ^ uint32_t(hash >> 32); }
|
|
||||||
uint64_t val64() const { return uint64_t(hash); }
|
constexpr uint32_t val32() const { return uint32_t(hash) ^ uint32_t(hash >> 32); }
|
||||||
size_t valSizeT() const { return size_t(hash); }
|
constexpr uint64_t val64() const { return uint64_t(hash); }
|
||||||
|
constexpr size_t valSizeT() const { return size_t(hash); }
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T valT() const;
|
constexpr T valT() const;
|
||||||
Hash& operator=(const Hash& other) {
|
|
||||||
hash = other.hash;
|
constexpr Hash& operator=(const Hash& other) = default;
|
||||||
return *this;
|
constexpr Hash& operator=(Hash&& other) noexcept = default;
|
||||||
}
|
constexpr bool operator==(const Hash& other) const { return hash == other.hash; }
|
||||||
bool operator==(const Hash& other) const { return hash == other.hash; }
|
constexpr bool operator!=(const Hash& other) const { return hash != other.hash; }
|
||||||
bool operator!=(const Hash& other) const { return hash != other.hash; }
|
constexpr bool operator<(const Hash& other) const { return hash < other.hash; }
|
||||||
bool operator<(const Hash& other) const { return hash < other.hash; }
|
constexpr bool operator>(const Hash& other) const { return hash > other.hash; }
|
||||||
bool operator>(const Hash& other) const { return hash > other.hash; }
|
constexpr bool operator<=(const Hash& other) const { return hash <= other.hash; }
|
||||||
bool operator<=(const Hash& other) const { return hash <= other.hash; }
|
constexpr bool operator>=(const Hash& other) const { return hash >= other.hash; }
|
||||||
bool operator>=(const Hash& other) const { return hash >= other.hash; }
|
constexpr explicit operator bool() const { return hash != 0; }
|
||||||
};
|
};
|
||||||
template <>
|
template <>
|
||||||
inline uint32_t Hash::valT<uint32_t>() const {
|
constexpr uint32_t Hash::valT<uint32_t>() const {
|
||||||
return val32();
|
return val32();
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
inline uint64_t Hash::valT<uint64_t>() const {
|
constexpr uint64_t Hash::valT<uint64_t>() const {
|
||||||
return val64();
|
return val64();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue