31#ifndef FENNEC_CONTAINERS_MAP_H
32#define FENNEC_CONTAINERS_MAP_H
79template<
typename KeyT,
typename ValueT,
typename Hash = hash<KeyT>,
typename Alloc = allocator<pair<KeyT, ValueT>>>
96 constexpr size_t operator()(
const elem_t& p)
const {
97 return hash_t::operator()(p.
first);
102 struct key_equals : equality<KeyT> {
103 constexpr bool operator()(
const elem_t& a,
const elem_t& b)
const {
104 return equality<KeyT>::operator()(a.first, b.first);
116 constexpr map() =
default;
132 constexpr size_t size()
const {
161 auto it = _set.
at(this->_find(key));
162 return it ? &it->
second :
nullptr;
170 auto it = _set.
at(this->_find(key));
171 return it ? &it->
second :
nullptr;
179 template<
typename...ArgsT>
181 auto it = _set.
at(this->_find(fennec::forward<ArgsT>(args)...));
182 return it ? &it->
second :
nullptr;
190 template<
typename...ArgsT>
192 auto it = _set.
at(this->_find(fennec::forward<ArgsT>(args)...));
193 return it ? &it->
second :
nullptr;
208 this->_insert(fennec::forward<elem_t>(
pair));
214 template<
typename...ArgsT>
215 constexpr void emplace(
const KeyT& key, ArgsT&&...args) {
216 this->_insert(key, fennec::forward<ArgsT>(args)...);
222 template<
typename...ArgsT>
224 this->_insert(fennec::forward<ArgsT>(args)...);
231 _set.
erase(this->_find(fennec::forward<KeyT>(key)));
237 constexpr void erase(
const KeyT& key) {
238 _set.
erase(this->_find(key));
245 template<
typename...ArgsT>
246 constexpr void erase(ArgsT&&...args) {
247 _set.
erase(this->_find(fennec::forward<ArgsT>(args)...));
285 template<
typename...ArgsT>
286 set_t::iterator _find(ArgsT&&...args)
const {
288 pair<KeyT,
char[
sizeof(ValueT)]> root;
292 fennec::destruct(&root);
295 .root = { KeyT(fennec::forward<ArgsT>(args)...), 0 }
297 return _set.find(trick.val);
300 template<
typename...ArgsT>
301 constexpr void _insert(ArgsT&&...args) {
302 elem_t elem(fennec::forward<ArgsT>(args)...);
303 auto it = this->_find(elem.first);
304 if (it != _set.end()) {
307 _set.insert(fennec::move(elem));
A header containing the definition for a container holding a pair of values.
A header containing the definition for a set of unique values.
typename _rebind< Alloc, TypeT >::type rebind
Rebinds the allocator type to produce an element type of type TypeT
Definition allocator.h:134
Data Structure defining a mapping of key to value .
Definition map.h:80
constexpr iterator begin()
C++ Iterator Specification begin()
Definition map.h:267
constexpr const value_t * operator[](ArgsT &&...args) const
Argument Key Const Access Operator.
Definition map.h:191
constexpr value_t * operator[](ArgsT &&...args)
Argument Key Access Operator.
Definition map.h:180
constexpr size_t empty() const
Definition map.h:138
constexpr size_t capacity() const
Definition map.h:144
set_t::iterator iterator
Iterator type.
Definition map.h:92
void clear()
Clears the map destructing all elements.
Definition map.h:252
constexpr size_t size() const
Definition map.h:132
constexpr void insert(elem_t &&pair)
Key-Value Insertion.
Definition map.h:207
typename allocator_traits< Alloc >::template rebind< elem_t > alloc_t
Rebinds the allocator type to nodes.
Definition map.h:89
constexpr map()=default
Default Constructor, initializes empty map.
constexpr void erase(ArgsT &&...args)
Argument Erase.
Definition map.h:246
constexpr void emplace(ArgsT &&...args)
Key-Value Insertion.
Definition map.h:223
constexpr void erase(KeyT &&key)
Erase a key.
Definition map.h:230
constexpr value_t * operator[](const KeyT &key)
Key Access Operator.
Definition map.h:160
KeyT key_t
The key type.
Definition map.h:86
Hash hash_t
The hash type.
Definition map.h:90
ValueT value_t
The value type.
Definition map.h:87
constexpr ~map()=default
Destructor, Destructs all elements and releases the allocation.
constexpr void emplace(const KeyT &key, ArgsT &&...args)
Key-Value Insertion.
Definition map.h:215
constexpr void erase(const KeyT &key)
Erase a key.
Definition map.h:237
pair< KeyT, ValueT > elem_t
then node type
Definition map.h:88
constexpr iterator end()
C++ Iterator Specification end()
Definition map.h:275
set< elem_t, key_hash, key_equals, alloc_t > set_t
The underlying set.
Definition map.h:91
constexpr const value_t * operator[](const KeyT &key) const
Key Const Access Operator.
Definition map.h:169
Struct for holding a pair of values.
Definition pair.h:48
TypeT1 second
The second value in the pair.
Definition pair.h:53
TypeT0 first
The first value in the pair.
Definition pair.h:52
constexpr size_t size() const
Definition set.h:180
constexpr size_t capacity() const
Definition set.h:192
constexpr elem_t * at(const iterator &it)
Iterator Access.
Definition set.h:265
constexpr iterator begin() const
Definition set.h:364
constexpr iterator end() const
Definition set.h:374
constexpr void erase(iterator it)
Element Erase.
Definition set.h:317
constexpr remove_reference_t< T > && move(T &&x) noexcept
produces an x-value type to indicate x may be "moved"
Definition utility.h:92