1#ifndef UNORDERED_MAP_WRAPPER_HPP
2#define UNORDERED_MAP_WRAPPER_HPP
4#include <unordered_map>
14template <
typename Key,
typename Value>
struct MapSignals {
81template <
typename Key,
typename Value,
typename Hash = std::hash<Key>,
typename KeyEq = std::equal_to<Key>>
88 using map_type = std::unordered_map<Key, Value, Hash, KeyEq>;
103 bool empty() const noexcept {
return map_.empty(); }
117 Value &
at(
const Key &
k) {
return map_.at(
k); }
118 const Value &
at(
const Key &
k)
const {
return map_.at(
k); }
122 return map_.insert_or_assign(key, std::move(value));
125 template <
typename... Args> std::pair<iterator, bool>
try_emplace(
const Key &key, Args &&...args) {
126 return map_.try_emplace(key, std::forward<Args>(args)...);
132 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&...args) {
133 auto [it, inserted] = map_.emplace(std::forward<Args>(args)...);
136 return {it, inserted};
146 auto it = map_.find(key);
147 if (it == map_.end())
150 Value old_value = it->second;
151 size_type num_elts_erased = map_.erase(key);
153 if (num_elts_erased == 1)
156 return num_elts_erased;
161 void clear() noexcept { map_.clear(); }
164 auto it = map_.find(key);
165 if (it == map_.end())
167 it->second = std::move(new_value);
Definition input_state.hpp:168
size_type erase(const Key &key)
runs the internal call and emits an erased signal if succeeded
Definition reactive_unordered_map.hpp:144
iterator end() noexcept
Definition reactive_unordered_map.hpp:108
std::pair< iterator, bool > insert_or_assign(const Key &key, Value &&value)
Definition reactive_unordered_map.hpp:121
const Value & at(const Key &k) const
Definition reactive_unordered_map.hpp:118
typename map_type::iterator iterator
Definition reactive_unordered_map.hpp:89
bool update_if_exists(const Key &key, Value &&new_value)
Definition reactive_unordered_map.hpp:163
std::pair< iterator, bool > try_emplace(const Key &key, Args &&...args)
Definition reactive_unordered_map.hpp:125
map_signals::Erased erased_signal
Definition reactive_unordered_map.hpp:95
std::unordered_map< Key, Value, Hash, KeyEq > map_type
Definition reactive_unordered_map.hpp:88
ReactiveUnorderedMap()=default
iterator find(const Key &k)
Definition reactive_unordered_map.hpp:113
MapSignals< Key, Value > map_signals
Definition reactive_unordered_map.hpp:93
bool empty() const noexcept
Definition reactive_unordered_map.hpp:103
const_iterator end() const noexcept
Definition reactive_unordered_map.hpp:110
SignalEmitter signal_emitter
Definition reactive_unordered_map.hpp:100
Value & at(const Key &k)
Definition reactive_unordered_map.hpp:117
Value & operator[](const Key &key)
Definition reactive_unordered_map.hpp:139
iterator erase(iterator pos)
Definition reactive_unordered_map.hpp:159
const_iterator begin() const noexcept
Definition reactive_unordered_map.hpp:109
Value mapped_type
Definition reactive_unordered_map.hpp:85
iterator begin() noexcept
Definition reactive_unordered_map.hpp:107
const_iterator find(const Key &k) const
Definition reactive_unordered_map.hpp:114
typename map_type::const_iterator const_iterator
Definition reactive_unordered_map.hpp:90
void clear() noexcept
Definition reactive_unordered_map.hpp:161
bool contains(const Key &k) const
Definition reactive_unordered_map.hpp:115
std::size_t size_type
Definition reactive_unordered_map.hpp:87
map_signals::Inserted inserted_signal
Definition reactive_unordered_map.hpp:94
std::pair< const Key, Value > value_type
Definition reactive_unordered_map.hpp:86
size_type size() const noexcept
Definition reactive_unordered_map.hpp:104
std::pair< iterator, bool > emplace(Args &&...args)
runs the internal call and emits an inserted signal if succeeded
Definition reactive_unordered_map.hpp:132
Key key_type
Definition reactive_unordered_map.hpp:84
void reserve(size_type n)
Definition reactive_unordered_map.hpp:105
A type-safe signal emitter that allows different signal types (represented as structs).
Definition signal_emitter.hpp:43
Definition reactive_unordered_map.hpp:35
Definition reactive_unordered_map.hpp:29
const Key & key
Definition reactive_unordered_map.hpp:30
const Value & old_value
Definition reactive_unordered_map.hpp:31
Definition reactive_unordered_map.hpp:16
const Value & value
Definition reactive_unordered_map.hpp:18
const Key & key
Definition reactive_unordered_map.hpp:17
Definition reactive_unordered_map.hpp:38
std::size_t new_bucket_count
Definition reactive_unordered_map.hpp:40
std::size_t old_bucket_count
Definition reactive_unordered_map.hpp:39
Definition reactive_unordered_map.hpp:44
std::size_t new_capacity
Definition reactive_unordered_map.hpp:45
Definition reactive_unordered_map.hpp:22
const Value & old_value
Definition reactive_unordered_map.hpp:24
const Key & key
Definition reactive_unordered_map.hpp:23
const Value & new_value
Definition reactive_unordered_map.hpp:25
Definition reactive_unordered_map.hpp:14