13 #ifndef __STOUT_HASHMAP_HPP__ 14 #define __STOUT_HASHMAP_HPP__ 19 #include <unordered_map> 31 template <
typename Key,
33 typename Hash =
typename std::conditional<
34 std::is_enum<Key>::value,
37 typename Equal = std::equal_to<Key>>
38 class hashmap :
public std::unordered_map<Key, Value, Hash, Equal>
51 std::unordered_map<Key, Value, Hash, Equal>::reserve(map.size());
53 for (
auto iterator = map.begin(); iterator != map.end(); ++iterator) {
54 std::unordered_map<Key, Value, Hash, Equal>::emplace(
68 std::unordered_map<Key, Value, Hash, Equal>::insert(
69 std::make_move_iterator(
map.begin()),
70 std::make_move_iterator(
map.end()));
76 std::unordered_map<Key, Value, Hash, Equal>::reserve(
list.size());
78 for (
auto iterator =
list.begin(); iterator !=
list.end(); ++iterator) {
79 std::unordered_map<Key, Value, Hash, Equal>::emplace(
88 return std::unordered_map<Key, Value, Hash, Equal>::count(key) > 0;
104 void put(
const Key& key, Value&& value)
106 std::unordered_map<Key, Value, Hash, Equal>::erase(key);
107 std::unordered_map<Key, Value, Hash, Equal>::insert(
108 std::pair<Key, Value>(key, std::move(value)));
113 void put(
const Key& key,
const Value& value)
115 std::unordered_map<Key, Value, Hash, Equal>::erase(key);
116 std::unordered_map<Key, Value, Hash, Equal>::insert(
117 std::pair<Key, Value>(key, value));
124 if (it == std::unordered_map<Key, Value, Hash, Equal>::end()) {
144 std::vector<Value> result;
148 result.push_back(value);
156 template <
typename K,
typename V>
157 std::ostream& operator<<(std::ostream& stream, const hashmap<K, V>&
map)
162 #endif // __STOUT_HASHMAP_HPP__ Definition: option.hpp:29
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
hashmap(std::map< Key, Value > &&map)
Definition: hashmap.hpp:64
hashmap(const std::map< Key, Value > &map)
Definition: hashmap.hpp:49
Definition: hashset.hpp:53
hashmap()
Definition: hashmap.hpp:43
Definition: hashmap.hpp:38
hashmap(std::initializer_list< std::pair< Key, Value >> list)
Definition: hashmap.hpp:74
void put(const Key &key, const Value &value)
Definition: hashmap.hpp:113
#define foreachvalue(VALUE, ELEMS)
Definition: foreach.hpp:77
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
void put(const Key &key, Value &&value)
Definition: hashmap.hpp:104
Iterable< V > map(F &&f, const Iterable< U, Us... > &input)
Definition: lambda.hpp:46
#define foreachkey(KEY, ELEMS)
Definition: foreach.hpp:74
Try< uint32_t > type(const std::string &path)
bool contains_value(const Value &v) const
Definition: hashmap.hpp:92
std::string stringify(int flags)
hashset< Key > keys() const
Definition: hashmap.hpp:132
bool contains(const Key &key) const
Definition: hashmap.hpp:86
std::vector< Value > values() const
Definition: hashmap.hpp:142
Definition: hashset.hpp:31
Try< std::list< std::string > > find(const std::string &directory, const std::string &pattern)
Definition: find.hpp:37