31#ifndef ETL_FLAT_MAP_INCLUDED
32#define ETL_FLAT_MAP_INCLUDED
62 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey> >
73 typedef ETL_OR_STD::pair<const TKey, TMapped> value_type;
74 typedef TKey key_type;
75 typedef TMapped mapped_type;
76 typedef TKeyCompare key_compare;
77 typedef value_type& reference;
78 typedef const value_type& const_reference;
80 typedef value_type&& rvalue_reference;
82 typedef value_type* pointer;
83 typedef const value_type* const_pointer;
84 typedef size_t size_type;
86 typedef const key_type& const_key_reference;
88 typedef key_type&& rvalue_key_reference;
90 typedef mapped_type& mapped_reference;
91 typedef const mapped_type& const_mapped_reference;
96 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
97 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
98 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
109 bool operator ()(
const value_type& element, key_type key)
const
111 return comp(element.first, key);
114 bool operator ()(key_type key,
const value_type& element)
const
116 return comp(key, element.first);
209 const_reverse_iterator
rend()
const
227 const_reverse_iterator
crend()
const
238 mapped_reference
operator [](rvalue_key_reference key)
243 if ((i_element ==
end()) ||
compare(key, i_element->first))
245 insert_default_value(i_element, etl::move(key));
248 return i_element->second;
262 if ((i_element ==
end()) || compare(key, i_element->first))
264 insert_default_value(i_element, key);
267 return i_element->second;
276 mapped_reference
at(const_key_reference key)
283 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
284 mapped_reference
at(
const K& key)
296 const_mapped_reference
at(const_key_reference key)
const
303 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
304 const_mapped_reference
at(
const K& key)
const
317 template <
typename TIterator>
318 void assign(TIterator first, TIterator last)
320#if ETL_IS_DEBUG_BUILD
321 difference_type d = etl::distance(first, last);
327 while (first != last)
339 ETL_OR_STD::pair<iterator, bool>
insert(const_reference value)
343 ETL_OR_STD::pair<iterator, bool> result(i_element,
false);
346 if ((i_element ==
end()) || compare(value.first, i_element->first))
348 result = insert_value(i_element, value);
360 ETL_OR_STD::pair<iterator, bool>
insert(rvalue_reference value)
364 ETL_OR_STD::pair<iterator, bool> result(i_element,
false);
367 if ((i_element ==
end()) ||
compare(value.first, i_element->first))
370 result = insert_value(i_element, etl::move(value));
385 return insert(value).first;
397 return insert(etl::move(value)).first;
408 template <
class TIterator>
409 void insert(TIterator first, TIterator last)
411 while (first != last)
421 ETL_OR_STD::pair<iterator, bool>
emplace(
const value_type& value)
423 return emplace(value.first, value.second);
426#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
430 template <
typename ... Args>
431 ETL_OR_STD::pair<iterator, bool>
emplace(const_key_reference key, Args && ... args)
436 value_type* pvalue = storage.
allocate<value_type>();
438 ::new ((
void*)
etl::
addressof(pvalue->second)) mapped_type(
etl::forward<Args>(args)...);
442 ETL_OR_STD::
pair<
iterator,
bool> result(i_element, false);
445 if ((i_element ==
end()) ||
compare(key, i_element->first))
447 ETL_INCREMENT_DEBUG_COUNT
452 pvalue->~value_type();
464 template <
typename T1>
465 ETL_OR_STD::pair<iterator, bool>
emplace(const_key_reference key,
const T1& value1)
470 value_type* pvalue = storage.
allocate<value_type>();
472 ::new ((
void*)
etl::addressof(pvalue->second)) mapped_type(value1);
476 ETL_OR_STD::pair<iterator, bool> result(i_element,
false);
479 if ((i_element ==
end()) || compare(key, i_element->first))
481 ETL_INCREMENT_DEBUG_COUNT
486 pvalue->~value_type();
496 template <
typename T1,
typename T2>
497 ETL_OR_STD::pair<iterator, bool>
emplace(const_key_reference key,
const T1& value1,
const T2& value2)
502 value_type* pvalue = storage.
allocate<value_type>();
504 ::new ((
void*)
etl::addressof(pvalue->second)) mapped_type(value1, value2);
508 ETL_OR_STD::pair<iterator, bool> result(i_element,
false);
511 if ((i_element ==
end()) || compare(key, i_element->first))
513 ETL_INCREMENT_DEBUG_COUNT
518 pvalue->~value_type();
528 template <
typename T1,
typename T2,
typename T3>
529 ETL_OR_STD::pair<iterator, bool>
emplace(const_key_reference key,
const T1& value1,
const T2& value2,
const T3& value3)
534 value_type* pvalue = storage.
allocate<value_type>();
536 ::new ((
void*)
etl::addressof(pvalue->second)) mapped_type(value1, value2, value3);
540 ETL_OR_STD::pair<iterator, bool> result(i_element,
false);
543 if ((i_element ==
end()) || compare(key, i_element->first))
545 ETL_INCREMENT_DEBUG_COUNT
550 pvalue->~value_type();
560 template <
typename T1,
typename T2,
typename T3,
typename T4>
561 ETL_OR_STD::pair<iterator, bool>
emplace(const_key_reference key,
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
566 value_type* pvalue = storage.
allocate<value_type>();
568 ::new ((
void*)
etl::addressof(pvalue->second)) mapped_type(value1, value2, value3, value4);
572 ETL_OR_STD::pair<iterator, bool> result(i_element,
false);
575 if ((i_element ==
end()) || compare(key, i_element->first))
577 ETL_INCREMENT_DEBUG_COUNT
582 pvalue->~value_type();
596 size_t erase(const_key_reference key)
600 if (i_element ==
end())
606 i_element->~value_type();
609 ETL_DECREMENT_DEBUG_COUNT;
616 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
617 size_t erase(K&& key)
621 if (i_element ==
end())
627 i_element->~value_type();
630 ETL_DECREMENT_DEBUG_COUNT;
642 i_element->~value_type();
644 ETL_DECREMENT_DEBUG_COUNT
654 i_element->~value_type();
656 ETL_DECREMENT_DEBUG_COUNT
676 ETL_DECREMENT_DEBUG_COUNT
703 ETL_RESET_DEBUG_COUNT
719 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
738 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
739 const_iterator
find(
const K& key)
const
750 size_t count(const_key_reference key)
const
757 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
758 size_t count(
const K& key)
const
776 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
795 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
814 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
833 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
845 ETL_OR_STD::pair<iterator, iterator>
equal_range(const_key_reference key)
852 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
853 ETL_OR_STD::pair<iterator, iterator>
equal_range(
const K& key)
864 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(const_key_reference key)
const
871 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
872 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const
888 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
914 move_container(etl::move(rhs));
1000 while (first != last)
1005 this->
insert(etl::move(*first));
1019 TKeyCompare compare;
1022 ETL_DECLARE_DEBUG_COUNT
1026 template <
typename TValueType>
1027 ETL_OR_STD::pair<iterator, bool> insert_value(iterator i_element, TValueType&& value)
1031 value_type* pvalue = storage.allocate<value_type>();
1032 ::new (pvalue) value_type(etl::forward<TValueType>(value));
1033 ETL_INCREMENT_DEBUG_COUNT
1038 ETL_OR_STD::pair<iterator, bool> insert_value(iterator i_element, const_reference value)
1042 value_type* pvalue = storage.allocate<value_type>();
1043 ::new (pvalue) value_type(value_type(value));
1044 ETL_INCREMENT_DEBUG_COUNT
1051 ETL_OR_STD::pair<iterator, bool> insert_default_value(iterator i_element, rvalue_key_reference key)
1055 value_type* pvalue = storage.allocate<value_type>();
1057 ::new ((
void*)
etl::
addressof(pvalue->second)) mapped_type();
1058 ETL_INCREMENT_DEBUG_COUNT
1060 return refmap_t::
insert_at(i_element, *pvalue);
1065 ETL_OR_STD::pair<iterator, bool> insert_default_value(iterator i_element, const_key_reference key)
1069 value_type* pvalue = storage.allocate<value_type>();
1071 ::new ((
void*)
etl::
addressof(pvalue->second)) mapped_type();
1072 ETL_INCREMENT_DEBUG_COUNT
1074 return refmap_t::
insert_at(i_element, *pvalue);
1080#if defined(ETL_POLYMORPHIC_FLAT_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS)
1100 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
1113 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
1116 return !(lhs == rhs);
1127 template <
typename TKey,
typename TValue, const
size_t MAX_SIZE_,
typename TCompare = etl::less<TKey> >
1132 static ETL_CONSTANT
size_t MAX_SIZE = MAX_SIZE_;
1138 :
etl::
iflat_map<TKey, TValue, TCompare>(lookup, storage)
1146 :
etl::
iflat_map<TKey, TValue, TCompare>(lookup, storage)
1156 :
etl::
iflat_map<TKey, TValue, TCompare>(lookup, storage)
1160 this->move_container(etl::move(other));
1171 template <
typename TIterator>
1173 :
etl::
iflat_map<TKey, TValue, TCompare>(lookup, storage)
1175 this->
assign(first, last);
1178#if ETL_HAS_INITIALIZER_LIST
1182 flat_map(std::initializer_list<
typename etl::iflat_map<TKey, TValue, TCompare>::value_type> init)
1183 :
etl::
iflat_map<TKey, TValue, TCompare>(lookup, storage)
1185 this->
assign(init.begin(), init.end());
1218 this->move_container(etl::move(rhs));
1227 typedef typename etl::iflat_map<TKey, TValue, TCompare>::value_type node_t;
1236 template <
typename TKey,
typename TValue, const
size_t MAX_SIZE_,
typename TCompare>
1237 ETL_CONSTANT
size_t flat_map<TKey, TValue, MAX_SIZE_, TCompare>::MAX_SIZE;
1242#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
1243 template <
typename... TPairs>
1244 flat_map(TPairs...) -> flat_map<
typename etl::nth_type_t<0, TPairs...>::first_type,
1245 typename etl::nth_type_t<0, TPairs...>::second_type,
1252#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
1253 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey>,
typename... TPairs>
1254 constexpr auto make_flat_map(TPairs&&... pairs) ->
etl::flat_map<TKey, TMapped,
sizeof...(TPairs), TKeyCompare>
1256 return { {etl::forward<TPairs>(pairs)...} };
Definition: reference_flat_map.h:218
Definition: reference_flat_map.h:134
#define ETL_ASSERT(b, e)
Definition: error_handler.h:316
ETL_OR_STD::pair< iterator, bool > emplace(const_key_reference key, const T1 &value1, const T2 &value2)
Emplaces a value to the map.
Definition: flat_map.h:497
const_iterator lower_bound(const_key_reference key) const
Definition: flat_map.h:788
size_t count(const_key_reference key) const
Definition: flat_map.h:750
size_type max_size() const
Definition: flat_map.h:960
reverse_iterator rbegin()
Definition: flat_map.h:182
iterator begin()
Definition: flat_map.h:128
ETL_OR_STD::pair< iterator, iterator > equal_range(const_key_reference key)
Definition: flat_map.h:845
~flat_map()
Destructor.
Definition: flat_map.h:1192
void clear()
Clears the flat_map.
Definition: flat_map.h:685
iflat_map(lookup_t &lookup_, storage_t &storage_)
Constructor.
Definition: flat_map.h:979
size_t available() const
Definition: flat_map.h:969
iterator find(const_key_reference key)
Definition: flat_map.h:712
const_reverse_iterator rbegin() const
Definition: flat_map.h:191
const_iterator upper_bound(const_key_reference key) const
Definition: flat_map.h:826
mapped_reference at(const_key_reference key)
Definition: flat_map.h:276
iterator erase(const_iterator i_element)
Definition: flat_map.h:652
~iflat_map()
Destructor.
Definition: flat_map.h:1087
iterator upper_bound(const_key_reference key)
Definition: flat_map.h:807
ETL_OR_STD::pair< iterator, bool > emplace(const value_type &value)
Emplaces a value to the map.
Definition: flat_map.h:421
const_iterator cend() const
Definition: flat_map.h:173
const_reverse_iterator crbegin() const
Definition: flat_map.h:218
const_mapped_reference at(const_key_reference key) const
Definition: flat_map.h:296
reverse_iterator rend()
Definition: flat_map.h:200
size_type capacity() const
Definition: flat_map.h:951
flat_map()
Constructor.
Definition: flat_map.h:1137
iterator erase(iterator i_element)
Definition: flat_map.h:640
ETL_OR_STD::pair< iterator, bool > insert(const_reference value)
Definition: flat_map.h:339
ETL_OR_STD::pair< iterator, bool > emplace(const_key_reference key, const T1 &value1)
Emplaces a value to the map.
Definition: flat_map.h:465
const_iterator cbegin() const
Definition: flat_map.h:164
size_t erase(const_key_reference key)
Definition: flat_map.h:596
bool contains(const_key_reference key) const
Check if the map contains the key.
Definition: flat_map.h:881
iflat_map & operator=(const iflat_map &rhs)
Assignment operator.
Definition: flat_map.h:898
ETL_OR_STD::pair< iterator, bool > emplace(const_key_reference key, const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Emplaces a value to the map.
Definition: flat_map.h:561
const_iterator begin() const
Definition: flat_map.h:137
const_iterator end() const
Definition: flat_map.h:155
bool full() const
Definition: flat_map.h:942
const_reverse_iterator rend() const
Definition: flat_map.h:209
iterator end()
Definition: flat_map.h:146
bool empty() const
Definition: flat_map.h:933
flat_map(const flat_map &other)
Copy constructor.
Definition: flat_map.h:1145
iterator erase(const_iterator first, const_iterator last)
Definition: flat_map.h:667
const_iterator find(const_key_reference key) const
Definition: flat_map.h:731
void insert(TIterator first, TIterator last)
Definition: flat_map.h:409
void assign(TIterator first, TIterator last)
Definition: flat_map.h:318
iterator insert(const_iterator, const_reference value)
Definition: flat_map.h:383
const_reverse_iterator crend() const
Definition: flat_map.h:227
flat_map(TIterator first, TIterator last)
Definition: flat_map.h:1172
ETL_OR_STD::pair< iterator, bool > emplace(const_key_reference key, const T1 &value1, const T2 &value2, const T3 &value3)
Emplaces a value to the map.
Definition: flat_map.h:529
iterator lower_bound(const_key_reference key)
Definition: flat_map.h:769
size_type size() const
Definition: flat_map.h:924
mapped_reference operator[](const_key_reference key)
Definition: flat_map.h:257
ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(const_key_reference key) const
Definition: flat_map.h:864
Definition: flat_map.h:1129
Definition: flat_map.h:64
ETL_CONSTEXPR17 T * addressof(T &t)
Definition: addressof.h:51
void release_all()
Release all objects in the pool.
Definition: ipool.h:248
T * allocate()
Definition: ipool.h:113
void release(const void *const p_object)
Definition: ipool.h:239
mapped_type & at(key_parameter_t key)
Definition: reference_flat_map.h:470
iterator begin()
Definition: reference_flat_map.h:360
void clear()
Clears the reference_flat_map.
Definition: reference_flat_map.h:658
ETL_OR_STD::pair< iterator, bool > insert_at(iterator i_element, value_type &value)
Definition: reference_flat_map.h:984
const_reverse_iterator crbegin() const
Definition: reference_flat_map.h:450
reverse_iterator rend()
Definition: reference_flat_map.h:432
size_t count(key_parameter_t key) const
Definition: reference_flat_map.h:762
iterator end()
Definition: reference_flat_map.h:378
const_iterator cbegin() const
Definition: reference_flat_map.h:396
ETL_OR_STD::pair< iterator, iterator > equal_range(key_parameter_t key)
Definition: reference_flat_map.h:857
size_t available() const
Definition: reference_flat_map.h:964
const_reverse_iterator crend() const
Definition: reference_flat_map.h:459
size_type max_size() const
Definition: reference_flat_map.h:955
bool empty() const
Definition: reference_flat_map.h:928
iterator lower_bound(key_parameter_t key)
Definition: reference_flat_map.h:781
reverse_iterator rbegin()
Definition: reference_flat_map.h:414
iterator upper_bound(key_parameter_t key)
Definition: reference_flat_map.h:819
size_type size() const
Definition: reference_flat_map.h:919
iterator find(key_parameter_t key)
Definition: reference_flat_map.h:668
const_iterator cend() const
Definition: reference_flat_map.h:405
size_t erase(key_parameter_t key)
Definition: reference_flat_map.h:591
bool full() const
Definition: reference_flat_map.h:937
size_type capacity() const
Definition: reference_flat_map.h:946
Definition: reference_flat_map.h:80
Definition: reference_flat_map.h:110
bitset_ext
Definition: absolute.h:38
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
Definition: type_traits_generator.h:2055
iterator
Definition: iterator.h:399
pair holds two objects of arbitrary type
Definition: utility.h:164