dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
hash.h
1#pragma once
2
3#include <cstddef>
4#include <functional>
5#include <map>
6#include <set>
7#include <utility>
8#include <vector>
9
10namespace dlinear::drake {
11
13template<class T>
14size_t hash_combine(size_t seed, const T &v);
15
16template<class T, class... Rest>
17size_t hash_combine(size_t seed, const T &v, Rest... rest) {
18 return hash_combine(hash_combine(seed, v), rest...);
19}
20
22template<typename It>
23size_t hash_range(It first, It last) {
24 size_t seed{};
25 for (; first != last; ++first) {
26 seed = hash_combine(seed, *first);
27 }
28 return seed;
29}
30
32template<class T>
33struct hash_value {
34 size_t operator()(const T &v) const { return std::hash<T>{}(v); }
35};
36
38template<class T1, class T2>
39struct hash_value<std::pair<T1, T2>> {
40 size_t operator()(const std::pair<T1, T2> &p) const {
41 return hash_combine(0, p.first, p.second);
42 }
43};
44
46template<class T>
47struct hash_value<std::vector<T>> {
48 size_t operator()(const std::vector<T> &vec) const {
49 return hash_range(vec.begin(), vec.end());
50 }
51};
52
54template<class T>
55struct hash_value<std::set<T>> {
56 size_t operator()(const std::set<T> &s) const {
57 return hash_range(s.begin(), s.end());
58 }
59};
60
62template<class T1, class T2>
63struct hash_value<std::map<T1, T2>> {
64 size_t operator()(const std::map<T1, T2> &map) const {
65 return hash_range(map.begin(), map.end());
66 }
67};
68
71template<class T>
72inline size_t hash_combine(size_t seed, const T &v) {
73 seed ^= hash_value<T>{}(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
74 return seed;
75}
76} // namespace dlinear::drake
77
std::set< Formula > map(const std::set< Formula > &formulas, const std::function< Formula(const Formula &)> &func)
Given formulas = {f₁, ..., fₙ} and a func : Formula → Formula, map(formulas, func) returns a set {fun...
Definition symbolic.cpp:47
STL namespace.
Computes the hash value of v using std::hash.
Definition hash.h:33