31#ifndef ETL_CONST_MULTIMAP_INCLUDED
32#define ETL_CONST_MULTIMAP_INCLUDED
51 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey>>
56 using key_type = TKey;
57 using value_type = ETL_OR_STD::pair<const TKey, TMapped>;
58 using mapped_type = TMapped;
59 using key_compare = TKeyCompare;
60 using const_reference =
const value_type&;
61 using const_pointer =
const value_type*;
62 using const_iterator =
const value_type*;
63 using size_type = size_t;
73 ETL_CONSTEXPR14
bool operator()(
const value_type& element1,
const value_type& element2)
const ETL_NOEXCEPT
75 return kcompare(element1.first, element2.first);
79 ETL_CONSTEXPR14
bool operator()(
const value_type& element,
const key_type& key)
const ETL_NOEXCEPT
81 return kcompare(element.first, key);
86 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
87 ETL_CONSTEXPR14
bool operator()(
const value_type& element,
const K& key)
const ETL_NOEXCEPT
89 return kcompare(element.first, key);
93 ETL_CONSTEXPR14
bool operator()(
const key_type& key,
const value_type& element)
const ETL_NOEXCEPT
95 return kcompare(key, element.first);
100 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
101 ETL_CONSTEXPR14
bool operator()(
const K& key,
const value_type& element)
const ETL_NOEXCEPT
103 return kcompare(key, element.first);
106 key_compare kcompare;
114 ETL_CONSTEXPR14
bool is_valid() const ETL_NOEXCEPT
123 ETL_CONSTEXPR14 const_iterator
begin() const ETL_NOEXCEPT
132 ETL_CONSTEXPR14 const_iterator
cbegin() const ETL_NOEXCEPT
141 ETL_CONSTEXPR14 const_iterator
end() const ETL_NOEXCEPT
143 return element_list_end;
150 ETL_CONSTEXPR14 const_iterator
cend() const ETL_NOEXCEPT
152 return element_list_end;
159 ETL_CONSTEXPR14 const_pointer
data() const ETL_NOEXCEPT
170 ETL_CONSTEXPR14 const_iterator find(
const key_type& key)
const ETL_NOEXCEPT
172 const_iterator itr = lower_bound(key);
174 if ((itr !=
end()) && (keys_are_equal(itr->first, key)))
189 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
190 ETL_CONSTEXPR14 const_iterator find(
const K& key)
const ETL_NOEXCEPT
192 const_iterator itr = lower_bound(key);
194 if ((itr !=
end()) && (keys_are_equal(itr->first, key)))
207 ETL_CONSTEXPR14
bool contains(
const key_type& key)
const ETL_NOEXCEPT
209 return find(key) !=
end();
218 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
219 ETL_CONSTEXPR14
bool contains(
const K& key)
const ETL_NOEXCEPT
221 return find(key) !=
end();
229 ETL_CONSTEXPR14 size_type count(
const key_type& key)
const ETL_NOEXCEPT
231 auto range = equal_range(key);
233 return size_type(etl::distance(range.first, range.second));
242 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
243 ETL_CONSTEXPR14 size_type count(
const K& key)
const ETL_NOEXCEPT
245 auto range = equal_range(key);
247 return size_type(etl::distance(range.first, range.second));
258 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(
const key_type& key)
const ETL_NOEXCEPT
260 return etl::equal_range(
begin(),
end(), key, vcompare);
272 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
273 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(
const K& key)
const ETL_NOEXCEPT
275 return etl::equal_range(
begin(),
end(), key, vcompare);
286 ETL_CONSTEXPR14 const_iterator lower_bound(
const key_type& key)
const ETL_NOEXCEPT
288 return etl::lower_bound(
begin(),
end(), key, vcompare);
299 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
300 ETL_CONSTEXPR14 const_iterator lower_bound(
const K& key)
const ETL_NOEXCEPT
302 return etl::lower_bound(
begin(),
end(), key, vcompare);
313 ETL_CONSTEXPR14 const_iterator upper_bound(
const key_type& key)
const ETL_NOEXCEPT
315 return etl::upper_bound(
begin(),
end(), key, vcompare);
326 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
327 ETL_CONSTEXPR14 const_iterator upper_bound(
const K& key)
const ETL_NOEXCEPT
329 return etl::upper_bound(
begin(),
end(), key, vcompare);
336 ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT
345 ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT
347 return (max_elements != 0) && (
size() == max_elements);
354 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
356 return size_type(element_list_end - element_list);
363 ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT
373 ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT
382 ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT
384 return vcompare.kcompare;
391 ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT
401 template <
typename... TElements>
402 ETL_CONSTEXPR14
explicit iconst_multimap(
const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
403 : element_list(element_list_)
404 , element_list_end{element_list_ + size_}
405 , max_elements(max_elements_)
414 ETL_CONSTEXPR14
bool keys_are_equal(
const key_type& key1,
const key_type& key2)
const ETL_NOEXCEPT
416 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
423 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
424 ETL_CONSTEXPR14
bool keys_are_equal(
const K1& key1,
const K2& key2)
const ETL_NOEXCEPT
426 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
429 value_compare vcompare;
431 const value_type* element_list;
432 const value_type* element_list_end;
433 size_type max_elements;
439 template <
typename TKey,
typename TMapped,
size_t Size,
typename TKeyCompare = etl::less<TKey>>
440 class const_multimap :
public iconst_multimap<TKey, TMapped, TKeyCompare>
444 using base_t = iconst_multimap<TKey, TMapped, TKeyCompare>;
446 using key_type =
typename base_t::key_type;
447 using value_type =
typename base_t::value_type;
448 using mapped_type =
typename base_t::mapped_type;
449 using key_compare =
typename base_t::key_compare;
450 using const_reference =
typename base_t::const_reference;
451 using const_pointer =
typename base_t::const_pointer;
452 using const_iterator =
typename base_t::const_iterator;
453 using size_type =
typename base_t::size_type;
455 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
456 static_assert((etl::is_default_constructible<mapped_type>::value),
"mapped_type must be default constructible");
465 template <
typename... TElements>
466 ETL_CONSTEXPR14
explicit const_multimap(TElements&&... elements) ETL_NOEXCEPT
467 : iconst_multimap<TKey, TMapped, TKeyCompare>(element_list,
sizeof...(elements), Size)
468 , element_list{etl::forward<TElements>(elements)...}
470 static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value),
"All elements must be value_type");
471 static_assert(
sizeof...(elements) <= Size,
"Number of elements exceeds capacity");
476 value_type element_list[Size];
483 template <
typename... TPairs>
484 const_multimap(TPairs...)
485 -> const_multimap<
typename etl::nth_type_t<0, TPairs...>::first_type,
typename etl::nth_type_t<0, TPairs...>::second_type,
sizeof...(TPairs)>;
491 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey>>
492 class const_multimap_ext :
public iconst_multimap<TKey, TMapped, TKeyCompare>
496 using base_t = iconst_multimap<TKey, TMapped, TKeyCompare>;
498 using key_type =
typename base_t::key_type;
499 using value_type =
typename base_t::value_type;
500 using mapped_type =
typename base_t::mapped_type;
501 using key_compare =
typename base_t::key_compare;
502 using const_reference =
typename base_t::const_reference;
503 using const_pointer =
typename base_t::const_pointer;
504 using const_iterator =
typename base_t::const_iterator;
505 using size_type =
typename base_t::size_type;
507 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
508 static_assert((etl::is_default_constructible<mapped_type>::value),
"mapped_type must be default constructible");
513 ETL_CONSTEXPR14 const_multimap_ext() ETL_NOEXCEPT
514 : iconst_multimap<TKey, TMapped, TKeyCompare>(
nullptr, 0, 0)
521 template <
size_type Size>
522 ETL_CONSTEXPR14
explicit const_multimap_ext(
const etl::span<const value_type, Size>& sp) ETL_NOEXCEPT
523 : iconst_multimap<TKey, TMapped, TKeyCompare>(sp.data(), Size, Size)
530 template <
size_type Size>
531 ETL_CONSTEXPR14
explicit const_multimap_ext(
const value_type (&begin_)[Size]) ETL_NOEXCEPT
532 : iconst_multimap<TKey, TMapped, TKeyCompare>(begin_, Size, Size)
541 template <
typename TElements,
size_t Size>
542 const_multimap_ext(
const etl::span<TElements, Size>&) -> const_multimap_ext<typename TElements::first_type, typename TElements::second_type>;
544 template <
typename TElements,
size_t Size>
545 const_multimap_ext(
const TElements (&)[Size]) -> const_multimap_ext<typename TElements::first_type, typename TElements::second_type>;
551 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
552 ETL_CONSTEXPR14
bool operator==(
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
553 const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
555 return etl::equal(lhs.begin(), lhs.end(), rhs.begin());
561 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
562 ETL_CONSTEXPR14
bool operator!=(
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
563 const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
565 return !(lhs == rhs);
575 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
576 ETL_CONSTEXPR14
bool operator<(
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
577 const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
579 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
589 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
590 ETL_CONSTEXPR14
bool operator>(
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
591 const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
604 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
605 ETL_CONSTEXPR14
bool operator<=(
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
606 const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
618 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
619 ETL_CONSTEXPR14
bool operator>=(
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
620 const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
ETL_NODISCARD ETL_CONSTEXPR14 bool is_sorted(TIterator begin, TIterator end)
Definition algorithm.h:1669
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1078
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition iterator.h:1470
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1130
TContainer::const_iterator cbegin(const TContainer &container)
Definition iterator.h:1156
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1144
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1090
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1434
TContainer::iterator end(TContainer &container)
Definition iterator.h:1166
TContainer::const_iterator cend(const TContainer &container)
Definition iterator.h:1186
TContainer::iterator begin(TContainer &container)
Definition iterator.h:1136
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1103
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1117