48template<
class Key,
class Value,
template<
class...>
class Storage=std::vector>
115 template<
class K,
class=std::enable_if_t<std::is_convertible<K, Key>{}>>
118 if (it !=
end())
return it->second;
119 storage.emplace_back( std::forward<K>(k), Value{} );
124 template<
class K,
class=std::enable_if_t<std::is_convertible<K, Key>{}>>
126 return [&k](
const std::pair<Key, Value>& kv){
127 return kv.first == k;
136 template<
class K,
class=std::enable_if_t<std::is_convertible<K, Key>{}>>
145 template<
class K,
class=std::enable_if_t<std::is_convertible<K, Key>{}>>
161 template<
class P,
class=std::enable_if_t<std::is_convertible<P,std::pair<Key, Value>>{}>>
164 auto it =
find(value.first);
166 storage.emplace_back( std::forward<P>(value) );
168 it->second = value.second;
180 for(
const auto &[k, v]: rhs) {
184 else if(it->second != v)
203 std::sort(x1.begin(), x1.end());
204 std::sort(x2.begin(), x2.end());
206 for(
auto it1 = x1.begin(), it2 = x2.begin();
223 template<
class K,
class V,
template<
class...>
class Storage>
232 size_t result = 0xDEADBEEF;
233 for(
const auto &[k,v]: key)
234 result ^= std::hash<K>()(k) ^ std::hash<V>()(v);
Flat associative map with pluggable storage.
Storage< std::pair< Key, Value > > storage_t
Underlying container type.
const_iterator cend() const
Return const iterator past the last element.
iterator find(K &&k)
Find the element with key k.
bool empty() const
Return true if the map contains no elements.
size_t size() const
Return the number of key-value pairs.
const_iterator end() const
Return const iterator past the last element.
iterator begin()
Return iterator to the first element.
flat_map(std::initializer_list< std::pair< Key, Value > > init)
Construct from an initializer list of key-value pairs.
const_iterator cbegin() const
Return const iterator to the first element.
void insert(P &&value)
Insert or update a key-value pair.
auto key_match(K &k)
Return a predicate matching key k.
decltype(begin(std::declval< const storage_t & >())) const_iterator
Const iterator.
const_iterator begin() const
Return const iterator to the first element.
size_t capacity() const
Return the current storage capacity.
iterator end()
Return iterator past the last element.
iterator erase(const_iterator it)
Remove the element at it.
storage_t storage
Contiguous key-value storage.
Value & operator[](K &&k)
Access or insert the value for key k.
const_iterator find(K &&k) const
Find the element with key k (const overload).
bool operator==(const flat_map &rhs) const
Compare two flat_maps for equality.
bool operator<(const flat_map &rhs) const
Lexicographic less-than comparison (order-independent on keys).
decltype(begin(std::declval< storage_t & >())) iterator
Mutable iterator.
void reserve(size_t n)
Reserve storage for at least n elements.
size_t operator()(const flat_map< K, V, Storage > &key) const
Compute the hash of a flat_map by XOR-folding element hashes.