mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
hash.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <cstddef>
5#include <functional>
6
7
8namespace std {
9
11template<typename Container>
12requires requires (Container C) { {C.cbegin() < C.cend() } -> std::same_as<bool>; } and
13 requires (Container C) { {C.cbegin() == C.cend() } -> std::same_as<bool>; } and
14 requires (Container C) { {C.cbegin() != C.cend() } -> std::same_as<bool>; } and
15 requires (Container C) { *C.cbegin(); }
16struct hash<Container>
17{
18 std::size_t operator()(const Container &C) const {
19 using value_type = decltype(*C.cbegin());
20 std::hash<std::decay_t<value_type>> h;
21 std::size_t value = 0xcbf29ce484222325UL;
22
23 for (const auto &elem : C) {
24 value ^= h(elem);
25 value *= 0x100000001b3UL;
26 }
27
28 return value;
29 }
30};
31
33template<typename T>
34struct hash<std::reference_wrapper<T>>
35{
36 std::size_t operator()(std::reference_wrapper<T> ref) const {
37 std::hash<std::decay_t<T>> h;
38 return h(ref.get());
39 }
40};
41
42template<typename T>
43bool operator==(std::reference_wrapper<T> left, std::reference_wrapper<T> right) { return left.get() == right.get(); }
44
45}
STL namespace.
bool operator==(std::reference_wrapper< T > left, std::reference_wrapper< T > right)
Definition: hash.hpp:43
and
Conveniance specialization to provide hasing of std::vector by computing a rolling hash over the elem...
Definition: hash.hpp:13
std::size_t operator()(const Container &C) const
Definition: hash.hpp:18
std::size_t operator()(std::reference_wrapper< T > ref) const
Definition: hash.hpp:36