flatten 20260225
This commit is contained in:
58
tjp/core/hash/Hash.h
Executable file
58
tjp/core/hash/Hash.h
Executable file
@@ -0,0 +1,58 @@
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user