13 #ifndef __STOUT_MULTIHASHMAP_HPP__ 14 #define __STOUT_MULTIHASHMAP_HPP__ 20 #include <unordered_map> 30 template <
typename Key,
32 typename Hash = std::hash<Key>,
33 typename Equal = std::equal_to<Key>>
34 class multihashmap :
public std::unordered_multimap<Key, Value, Hash, Equal>
42 void put(
const Key& key,
const Value& value);
43 std::list<Value>
get(
const Key& key)
const;
44 std::set<Key>
keys()
const;
45 bool remove(
const Key& key);
46 bool remove(
const Key& key,
const Value& value);
48 bool contains(
const Key& key,
const Value& value)
const;
52 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
54 const std::multimap<Key, Value>& multimap)
56 std::unordered_multimap<Key, Value, Hash, Equal>::reserve(multimap.size());
58 foreachpair (
const Key& key,
const Value& value, multimap) {
59 std::unordered_multimap<Key, Value, Hash, Equal>::emplace(key, value);
64 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
66 std::multimap<Key, Value>&& multimap)
68 std::unordered_multimap<Key, Value, Hash, Equal>::insert(
69 std::make_move_iterator(multimap.begin()),
70 std::make_move_iterator(multimap.end()));
74 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
76 std::initializer_list<std::pair<const Key, Value>>
list)
77 :
std::unordered_multimap<Key, Value, Hash, Equal>(
list) {}
80 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
85 std::unordered_multimap<Key, Value, Hash, Equal>::insert({key, value});
89 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
93 std::list<Value> values;
96 std::unordered_multimap<Key, Value, Hash, Equal>::equal_range(key);
98 for (
auto i = range.first; i != range.second; ++i) {
99 values.push_back(i->second);
106 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
117 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
120 return std::unordered_multimap<Key, Value, Hash, Equal>::erase(key) > 0;
124 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
130 std::unordered_multimap<Key, Value, Hash, Equal>::equal_range(key);
132 for (
auto i = range.first; i != range.second; ++i) {
133 if (i->second == value) {
134 std::unordered_multimap<Key, Value, Hash, Equal>::erase(i);
143 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
150 template <
typename Key,
typename Value,
typename Hash,
typename Equal>
153 const Value& value)
const 155 const std::list<Value> values =
get(key);
156 return std::find(values.begin(), values.end(), value) != values.end();
159 #endif // __STOUT_MULTIHASHMAP_HPP__ bool contains(const Key &key) const
Definition: multihashmap.hpp:144
Definition: type_utils.hpp:619
multihashmap()
Definition: multihashmap.hpp:37
void put(const Key &key, const Value &value)
Definition: multihashmap.hpp:81
Definition: multihashmap.hpp:34
#define foreachpair(KEY, VALUE, ELEMS)
Definition: foreach.hpp:51
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
std::list< Value > get(const Key &key) const
Definition: multihashmap.hpp:90
std::set< Key > keys() const
Definition: multihashmap.hpp:107
#define foreachkey(KEY, ELEMS)
Definition: foreach.hpp:74
bool remove(const Key &key)
Definition: multihashmap.hpp:118
Try< std::list< std::string > > find(const std::string &directory, const std::string &pattern)
Definition: find.hpp:37