31#ifndef ETL_CONST_MULTISET_INCLUDED
32#define ETL_CONST_MULTISET_INCLUDED
51 template <
typename TKey,
typename TKeyCompare = etl::less<TKey>>
56 using key_type = TKey;
57 using value_type = TKey;
58 using key_compare = TKeyCompare;
59 using value_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;
70 ETL_CONSTEXPR14
bool is_valid() const ETL_NOEXCEPT
79 ETL_CONSTEXPR14 const_iterator
begin() const ETL_NOEXCEPT
88 ETL_CONSTEXPR14 const_iterator
cbegin() const ETL_NOEXCEPT
97 ETL_CONSTEXPR14 const_iterator
end() const ETL_NOEXCEPT
99 return element_list_end;
106 ETL_CONSTEXPR14 const_iterator
cend() const ETL_NOEXCEPT
108 return element_list_end;
115 ETL_CONSTEXPR14 const_pointer
data() const ETL_NOEXCEPT
126 ETL_CONSTEXPR14 const_iterator find(
const key_type& key)
const ETL_NOEXCEPT
128 const_iterator itr = lower_bound(key);
130 if ((itr !=
end()) && (keys_are_equal(*itr, key)))
145 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
146 ETL_CONSTEXPR14 const_iterator find(
const K& key)
const ETL_NOEXCEPT
148 const_iterator itr = lower_bound(key);
150 if ((itr !=
end()) && (keys_are_equal(*itr, key)))
163 ETL_CONSTEXPR14
bool contains(
const key_type& key)
const ETL_NOEXCEPT
165 return find(key) !=
end();
174 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
175 ETL_CONSTEXPR14
bool contains(
const K& key)
const ETL_NOEXCEPT
177 return find(key) !=
end();
185 ETL_CONSTEXPR14 size_type count(
const key_type& key)
const ETL_NOEXCEPT
187 auto range = equal_range(key);
189 return size_type(etl::distance(range.first, range.second));
198 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
199 ETL_CONSTEXPR14 size_type count(
const K& key)
const ETL_NOEXCEPT
201 auto range = equal_range(key);
203 return size_type(etl::distance(range.first, range.second));
214 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(
const key_type& key)
const ETL_NOEXCEPT
216 return etl::equal_range(
begin(),
end(), key, vcompare);
228 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
229 ETL_CONSTEXPR14 ETL_OR_STD::pair<const_iterator, const_iterator> equal_range(
const K& key)
const ETL_NOEXCEPT
231 return etl::equal_range(
begin(),
end(), key, vcompare);
242 ETL_CONSTEXPR14 const_iterator lower_bound(
const key_type& key)
const ETL_NOEXCEPT
244 return etl::lower_bound(
begin(),
end(), key, vcompare);
255 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
256 ETL_CONSTEXPR14 const_iterator lower_bound(
const K& key)
const ETL_NOEXCEPT
258 return etl::lower_bound(
begin(),
end(), key, vcompare);
269 ETL_CONSTEXPR14 const_iterator upper_bound(
const key_type& key)
const ETL_NOEXCEPT
271 return etl::upper_bound(
begin(),
end(), key, vcompare);
282 template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
283 ETL_CONSTEXPR14 const_iterator upper_bound(
const K& key)
const ETL_NOEXCEPT
285 return etl::upper_bound(
begin(),
end(), key, vcompare);
292 ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT
301 ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT
303 return (max_elements != 0) && (
size() == max_elements);
310 ETL_CONSTEXPR14 size_type
size() const ETL_NOEXCEPT
312 return size_type(element_list_end - element_list);
319 ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT
329 ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT
338 ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT
347 ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT
357 template <
typename... TElements>
358 ETL_CONSTEXPR14
explicit iconst_multiset(
const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT
359 : element_list(element_list_)
360 , element_list_end{element_list_ + size_}
361 , max_elements(max_elements_)
370 ETL_CONSTEXPR14
bool keys_are_equal(
const key_type& key1,
const key_type& key2)
const ETL_NOEXCEPT
372 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
379 template <typename K1, typename K2, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
380 ETL_CONSTEXPR14
bool keys_are_equal(
const K1& key1,
const K2& key2)
const ETL_NOEXCEPT
382 return !key_compare()(key1, key2) && !key_compare()(key2, key1);
385 key_compare kcompare;
386 value_compare vcompare;
388 const value_type* element_list;
389 const value_type* element_list_end;
390 size_type max_elements;
396 template <
typename TKey,
size_t Size,
typename TKeyCompare = etl::less<TKey>>
397 class const_multiset :
public iconst_multiset<TKey, TKeyCompare>
401 using base_t = iconst_multiset<TKey, TKeyCompare>;
403 using key_type =
typename base_t::key_type;
404 using value_type =
typename base_t::value_type;
405 using key_compare =
typename base_t::key_compare;
406 using const_reference =
typename base_t::const_reference;
407 using const_pointer =
typename base_t::const_pointer;
408 using const_iterator =
typename base_t::const_iterator;
409 using size_type =
typename base_t::size_type;
411 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
420 template <
typename... TElements>
421 ETL_CONSTEXPR14
explicit const_multiset(TElements&&... elements) ETL_NOEXCEPT
422 : iconst_multiset<TKey, TKeyCompare>(element_list,
sizeof...(elements), Size)
423 , element_list{etl::forward<TElements>(elements)...}
425 static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value),
"All elements must be value_type");
426 static_assert(
sizeof...(elements) <= Size,
"Number of elements exceeds capacity");
431 value_type element_list[Size];
438 template <
typename... TElements>
439 const_multiset(TElements...) -> const_multiset<etl::nth_type_t<0, TElements...>,
sizeof...(TElements)>;
445 template <
typename TKey,
typename TKeyCompare = etl::less<TKey>>
446 class const_multiset_ext :
public iconst_multiset<TKey, TKeyCompare>
450 using base_t = iconst_multiset<TKey, TKeyCompare>;
452 using key_type =
typename base_t::key_type;
453 using value_type =
typename base_t::value_type;
454 using key_compare =
typename base_t::key_compare;
455 using const_reference =
typename base_t::const_reference;
456 using const_pointer =
typename base_t::const_pointer;
457 using const_iterator =
typename base_t::const_iterator;
458 using size_type =
typename base_t::size_type;
460 static_assert((etl::is_default_constructible<key_type>::value),
"key_type must be default constructible");
465 ETL_CONSTEXPR14 const_multiset_ext() ETL_NOEXCEPT
466 : iconst_multiset<TKey, TKeyCompare>(
nullptr, 0, 0)
473 template <
size_type Size>
474 ETL_CONSTEXPR14
explicit const_multiset_ext(
const etl::span<const value_type, Size>& sp) ETL_NOEXCEPT
475 : iconst_multiset<TKey, TKeyCompare>(sp.data(), Size, Size)
482 template <
size_type Size>
483 ETL_CONSTEXPR14
explicit const_multiset_ext(
const value_type (&begin_)[Size]) ETL_NOEXCEPT
484 : iconst_multiset<TKey, TKeyCompare>(begin_, Size, Size)
493 template <
typename TElements,
size_t Size>
494 const_multiset_ext(
const etl::span<TElements, Size>&) -> const_multiset_ext<TElements>;
496 template <
typename TElements,
size_t Size>
497 const_multiset_ext(
const TElements (&)[Size]) -> const_multiset_ext<TElements>;
503 template <
typename TKey,
typename TKeyCompare>
504 ETL_CONSTEXPR14
bool operator==(
const etl::iconst_multiset<TKey, TKeyCompare>& lhs,
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
506 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
512 template <
typename TKey,
typename TKeyCompare>
513 ETL_CONSTEXPR14
bool operator!=(
const etl::iconst_multiset<TKey, TKeyCompare>& lhs,
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
515 return !(lhs == rhs);
525 template <
typename TKey,
typename TKeyCompare>
526 ETL_CONSTEXPR14
bool operator<(
const etl::iconst_multiset<TKey, TKeyCompare>& lhs,
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
528 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
538 template <
typename TKey,
typename TKeyCompare>
539 ETL_CONSTEXPR14
bool operator>(
const etl::iconst_multiset<TKey, TKeyCompare>& lhs,
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
552 template <
typename TKey,
typename TKeyCompare>
553 ETL_CONSTEXPR14
bool operator<=(
const etl::iconst_multiset<TKey, TKeyCompare>& lhs,
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
565 template <
typename TKey,
typename TKeyCompare>
566 ETL_CONSTEXPR14
bool operator>=(
const etl::iconst_multiset<TKey, TKeyCompare>& lhs,
const etl::iconst_multiset<TKey, 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