1#ifndef BPMNOS_tuple_map_H
2#define BPMNOS_tuple_map_H
7#include <unordered_map>
16template<
typename T,
typename Allocator>
34template<
typename Key,
typename Value>
41 size_t operator()(
const std::vector<T>& vec)
const {
43 for (
const auto& elem : vec) {
44 hash ^= std::hash<T>()(elem) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
55 component(
const T& value) : value(value) {}
56 uintmax_t operator,(uintmax_t n)
const {
59 n ^= vector_hash<typename T::value_type>{}(value);
63 n ^= std::hash<T>()(value);
65 n ^= n << (
sizeof(uintmax_t) * 4 - 1);
66 return n ^ std::hash<uintmax_t>()(n);
72 size_t operator()(
const Tuple& tuple)
const {
73 return std::hash<uintmax_t>()( std::apply([](
const auto& ... xs) {
return (component(xs), ..., 0); }, tuple) );
77 std::unordered_map<Key, Value, tuple_hash> map;
80 using iterator =
typename std::unordered_map<Key, Value, tuple_hash>::iterator;
81 using const_iterator =
typename std::unordered_map<Key, Value, tuple_hash>::const_iterator;
82 using size_type =
typename std::unordered_map<Key, Value, tuple_hash>::size_type;
90 return map.contains(key);
140 std::pair<iterator, bool>
insert(
const std::pair<Key, Value>& value) {
141 return map.insert(value);
145 std::pair<iterator, bool>
emplace(
const Key& key,
const Value& value) {
146 return map.emplace(key,value);
150 return map.try_emplace(key,value);
158 return map.erase(key);
167 return map.count(key);
171 return map.find(key);
175 return map.find(key);
Wrapper class around std::unordered_map for maps with tuple keys.
size_type count(const Key &key) const
const_iterator cbegin() const noexcept
bool empty() const noexcept
const_iterator cend() const noexcept
typename std::unordered_map< Key, Value, tuple_hash >::size_type size_type
typename std::unordered_map< Key, Value, tuple_hash >::const_iterator const_iterator
typename std::unordered_map< Key, Value, tuple_hash >::iterator iterator
iterator begin() noexcept
Value & at(const Key &key)
Value & operator[](const Key &key)
std::pair< iterator, bool > try_emplace(const Key &key, const Value &value)
const Value & at(const Key &key) const
size_type size() const noexcept
const_iterator begin() const noexcept
bool contains(const Key &key) const
void swap(tuple_map &other) noexcept
const_iterator end() const noexcept
size_type erase(const Key &key)
std::pair< iterator, bool > insert(const std::pair< Key, Value > &value)
iterator find(const Key &key)
const_iterator find(const Key &key) const
std::pair< iterator, bool > emplace(const Key &key, const Value &value)
std::variant< bool, int, double, std::string > Value