ReXGlue SDK
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#include <functional>
16#include <span>
17#include <cstddef>
18#include <filesystem>
19#include <string>
20#include <string_view>
21#include <type_traits>
22
23#include <rex/types.h>
24#include <rex/platform.h>
25
26namespace rex {
27
33template <typename Key>
38 size_t operator()(const Key& key) const { return static_cast<size_t>(key); }
39};
40
46template <typename Key>
47struct KeyHasher {
51 size_t operator()(const Key& hashed_key) const {
52 return std::hash<std::remove_cvref_t<decltype(hashed_key.key)>>{}(hashed_key.key);
53 }
54};
55
61REX_API u64 HashXXH3(std::span<const u8> data);
62
64template <typename Key>
65struct XXHasher {
69 size_t operator()(const Key& key) const {
70 return static_cast<size_t>(
71 HashXXH3(std::span<const u8>(reinterpret_cast<const u8*>(&key), sizeof(key))));
72 }
73};
74
81REX_API std::string HashBytes(std::string_view data);
82
89REX_API std::string HashFile(const std::filesystem::path& path);
90
96inline size_t hash_combine(size_t hash) {
97 return hash;
98}
99
101template <typename T, typename... Ts>
102size_t hash_combine(size_t hash, const T& v, const Ts&... vs) {
103 std::hash<T> hasher;
104 hash ^= hasher(v) + 0x9E3779B9 + (hash << 6) + (hash >> 2);
105 return hash_combine(hash, vs...);
106}
107
108} // namespace rex
Definition app.h:36
std::string HashFile(const std::filesystem::path &path)
std::string HashBytes(std::string_view data)
size_t hash_combine(size_t hash)
Definition hash.h:96
u64 HashXXH3(std::span< const u8 > data)
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Definition hash.h:34
size_t operator()(const Key &key) const
Definition hash.h:38
Definition hash.h:47
size_t operator()(const Key &hashed_key) const
Definition hash.h:51
Definition hash.h:65
size_t operator()(const Key &key) const
Definition hash.h:69
Integer types, byte order wrappers and size literals.