Files
core_misc/tjp/core/hash/Hash.h
Timothy Prepscius fa54be052a flatten 20260225
2026-02-25 12:39:24 -05:00

59 lines
1.1 KiB
C++
Executable File

// TJP COPYRIGHT HEADER
#pragma once
#include <tjp/core/types/Types.h>
namespace tjp {
namespace core {
u32 hash32(const u8 *begin, size_t size);
u64 hash64(const u8 *begin, size_t size);
template<typename T>
T hash(const u8 *begin, size_t size);
template<typename T, typename U>
T hash_of(const U &u)
{
auto *begin_ = u.data();
auto *end_ = begin_ + u.size();
auto *begin = (u8 *)begin_;
auto *end = (u8 *)end_;
return hash<T>(begin, (end - begin));
}
template<typename T, typename U>
T hash_of_value(const U &u)
{
auto *begin_ = &u;
auto *end_ = begin_ + sizeof(u);
auto *begin = (u8 *)begin_;
auto *end = (u8 *)end_;
return hash<T>(begin, (end - begin));
}
template<>
inline
u32 hash<u32>(const u8 *begin, size_t size) { return hash32(begin, size); }
template<>
inline
s32 hash<s32>(const u8 *begin, size_t size) { return hash32(begin, size); }
template<>
inline
u64 hash<u64>(const u8 *begin, size_t size) { return hash64(begin, size); }
template<>
inline
s64 hash<s64>(const u8 *begin, size_t size) { return hash64(begin, size); }
} // namespace
} // namespace