18#include <unordered_map>
39 template <
class T1,
class T2>
40 inline size_t operator()(
const std::pair<T1, T2> &p)
const {
41 size_t lhs = std::hash<T1>()(p.first);
42 size_t rhs = std::hash<T2>()(p.second);
43 return lhs ^ (rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2));
50 template<
class... Types>
51 std::size_t
operator()(
const std::variant<Types...> &v)
const {
52 if (std::holds_alternative<std::int32_t>(v)) {
53 return std::hash<std::int32_t>()(std::get<std::int32_t>(v));
55 else if (std::holds_alternative<std::string>(v)) {
56 return std::hash<std::string>()(std::get<std::string>(v));
58 else if (std::holds_alternative<AnyTupleType>(v)) {
59 const auto &variant_vec = std::get<AnyTupleType>(v);
60 std::size_t hash = variant_vec.size();
61 for (
const auto &i : variant_vec) {
62 if (std::holds_alternative<std::int32_t>(i)) {
63 hash ^= std::hash<std::int32_t>()(std::get<std::int32_t>(i)) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
65 else if (std::holds_alternative<std::string>(i)) {
66 hash ^= std::hash<std::string>()(std::get<std::string>(i)) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
69 throw std::runtime_error(
"Invalid template parameters");
75 throw std::runtime_error(
"Invalid template parameters");
82 std::size_t
operator()(
const std::vector<IndexType> &v)
const {
83 std::size_t hash = v.size();
84 for (
const auto &i : v) {
85 hash ^=
IndexHash()(i) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
95 std::size_t hash = v.size();
96 for (
const auto &i : v) {
97 hash ^= std::hash<T>()(i) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
105 std::size_t
operator()(
const std::pair<IndexType, IndexType> &p)
const {
108 return lhs^(rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2));
Definition algorithm.hpp:24
Hash struct of IndexType.
Definition pairhash.hpp:49
std::size_t operator()(const std::variant< Types... > &v) const
Definition pairhash.hpp:51
Hash struct of std::pair<IndexType>.
Definition pairhash.hpp:104
std::size_t operator()(const std::pair< IndexType, IndexType > &p) const
Definition pairhash.hpp:105
Hash struct of std::vector<AnyIndexType>.
Definition pairhash.hpp:81
std::size_t operator()(const std::vector< IndexType > &v) const
Definition pairhash.hpp:82
hash class for std::pair
Definition pairhash.hpp:30
size_t operator()(const std::pair< T1, T2 > &p) const
generate hash for std::pair
Definition pairhash.hpp:40
Hash struct of std::vector<T>.
Definition pairhash.hpp:92
std::size_t operator()(const std::vector< T > &v) const
Definition pairhash.hpp:94