17 #ifndef MOMO_INCLUDE_GUARD_STDISH_SET
18 #define MOMO_INCLUDE_GUARD_STDISH_SET
20 #include "../TreeSet.h"
53 template<
typename TKey,
54 typename TLessFunc = std::less<TKey>,
55 typename TAllocator = std::allocator<TKey>,
56 typename TTreeSet = TreeSet<TKey, TreeTraitsStd<TKey, TLessFunc>, MemManagerStd<TAllocator>>>
60 typedef TTreeSet TreeSet;
97 template<
typename KeyArg>
98 struct IsValidKeyArg :
public TreeTraits::template IsValidKeyArg<KeyArg>
115 : mTreeSet(TreeTraits(), MemManager(alloc))
120 : mTreeSet(TreeTraits(lessFunc), MemManager(alloc))
124 template<
typename Iterator>
131 template<
typename Iterator>
134 :
set(lessFunc, alloc)
140 : mTreeSet(values, TreeTraits(), MemManager(alloc))
146 : mTreeSet(values, TreeTraits(lessFunc), MemManager(alloc))
151 : mTreeSet(std::move(right.mTreeSet))
156 noexcept(std::is_empty<allocator_type>::value)
157 : mTreeSet(pvCreateSet(
std::move(right), alloc))
162 : mTreeSet(right.mTreeSet)
167 : mTreeSet(right.mTreeSet, MemManager(alloc))
174 noexcept(std::is_empty<allocator_type>::value ||
175 std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
179 bool propagate = std::is_empty<allocator_type>::value ||
180 std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value;
182 mTreeSet = pvCreateSet(std::move(right), alloc);
191 bool propagate = std::is_empty<allocator_type>::value ||
192 std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value;
194 mTreeSet = TreeSet(right.mTreeSet, MemManager(alloc));
201 mTreeSet = TreeSet(values, mTreeSet.GetTreeTraits(), MemManager(
get_allocator()));
207 MOMO_ASSERT(std::allocator_traits<allocator_type>::propagate_on_container_swap::value
209 mTreeSet.Swap(right.mTreeSet);
229 return mTreeSet.GetBegin();
236 return mTreeSet.GetEnd();
277 return mTreeSet.GetTreeTraits().GetLessFunc();
287 return allocator_type(mTreeSet.GetMemManager().GetByteAllocator());
292 return std::allocator_traits<allocator_type>::max_size(
get_allocator());
297 return mTreeSet.GetCount();
302 return mTreeSet.IsEmpty();
312 return mTreeSet.Find(key);
317 template<
typename KeyArg>
321 return mTreeSet.Find(key);
330 return mTreeSet.GetKeyCount(key);
333 template<
typename KeyArg>
337 return mTreeSet.GetKeyCount(key);
342 return mTreeSet.ContainsKey(key);
345 template<
typename KeyArg>
349 return mTreeSet.ContainsKey(key);
354 return mTreeSet.GetLowerBound(key);
359 template<
typename KeyArg>
363 return mTreeSet.GetLowerBound(key);
372 return mTreeSet.GetUpperBound(key);
377 template<
typename KeyArg>
381 return mTreeSet.GetUpperBound(key);
393 if (iter ==
end() || mTreeSet.GetTreeTraits().IsLess(key, *iter))
394 return { iter, iter };
395 return { iter, std::next(iter) };
400 template<
typename KeyArg>
402 std::pair<const_iterator, const_iterator>>
equal_range(
const KeyArg& key)
const
419 if (!pvCheckHint(hint,
static_cast<const key_type&
>(value)))
420 return insert(std::move(value)).first;
421 return mTreeSet.Add(hint, std::move(value));
432 if (!pvCheckHint(hint, value))
433 return insert(value).first;
434 return mTreeSet.Add(hint, value);
442 std::move(NodeTypeProxy::GetExtractedItem(node)));
450 if (!pvCheckHint(hint, node.value()))
451 return insert(std::move(node)).position;
452 return mTreeSet.Add(hint, std::move(NodeTypeProxy::GetExtractedItem(node)));
455 template<
typename Iterator>
456 void insert(Iterator first, Iterator last)
461 void insert(std::initializer_list<value_type> values)
463 mTreeSet.Insert(values);
466 template<
typename... ValueArgs>
467 std::pair<iterator, bool>
emplace(ValueArgs&&... valueArgs)
469 MemManager& memManager = mTreeSet.GetMemManager();
471 typedef typename TreeSet::ItemTraits::template Creator<ValueArgs...> ValueCreator;
472 extItem.
Create(ValueCreator(memManager, std::forward<ValueArgs>(valueArgs)...));
477 template<
typename ValueArg>
479 std::pair<iterator, bool>>
emplace(ValueArg&& valueArg)
482 static_cast<const key_type&
>(valueArg), std::forward<ValueArg>(valueArg));
486 template<
typename... ValueArgs>
489 MemManager& memManager = mTreeSet.GetMemManager();
491 typedef typename TreeSet::ItemTraits::template Creator<ValueArgs...> ValueCreator;
492 extItem.
Create(ValueCreator(memManager, std::forward<ValueArgs>(valueArgs)...));
493 if (!pvCheckHint(hint, extItem.
GetItem()))
494 return mTreeSet.Insert(std::move(extItem)).position;
495 return mTreeSet.Add(hint, std::move(extItem));
498 template<
typename ValueArg>
502 if (!pvCheckHint(hint,
static_cast<const key_type&
>(valueArg)))
503 return emplace(std::forward<ValueArg>(valueArg)).first;
504 return mTreeSet.AddVar(hint, std::forward<ValueArg>(valueArg));
509 return mTreeSet.Remove(where);
516 return mTreeSet.Remove(first, last);
521 return mTreeSet.Remove(key);
524 template<
typename ValueFilter>
527 return cont.mTreeSet.Remove(valueFilter);
541 template<
typename Set>
554 return !(*
this == right);
557 #ifdef MOMO_HAS_THREE_WAY_COMPARISON
558 auto operator<=>(
const set& right)
const
559 requires requires (
const_reference ref) { std::tie(ref) <=> std::tie(ref); }
562 {
return std::tie(value1) <=> std::tie(value2); };
563 return std::lexicographical_compare_three_way(
begin(),
end(),
564 right.begin(), right.end(), comp);
569 return std::lexicographical_compare(
begin(),
end(), right.
begin(), right.
end());
574 return right < *
this;
579 return !(right < *
this);
584 return right <= *
this;
591 if (right.get_allocator() == alloc)
592 return std::move(right.mTreeSet);
593 TreeSet treeSet(right.mTreeSet.GetTreeTraits(), MemManager(alloc));
594 treeSet.MergeFrom(right.mTreeSet);
600 const TreeTraits& treeTraits = mTreeSet.GetTreeTraits();
602 : treeTraits.
IsLess(key1, key2);
607 if (hint !=
begin() && !pvIsOrdered(*std::prev(hint), key))
609 if (hint !=
end() && !pvIsOrdered(key, *hint))
618 template<
typename Iterator>
619 void pvInsert(Iterator first, Iterator last, std::true_type )
621 mTreeSet.Insert(first, last);
624 template<
typename Iterator>
625 void pvInsert(Iterator first, Iterator last, std::false_type )
627 for (Iterator iter = first; iter != last; ++iter)
643 template<
typename TKey,
644 typename TLessFunc = std::less<TKey>,
645 typename TAllocator = std::allocator<TKey>,
646 typename TTreeSet = TreeSet<TKey, TreeTraitsStd<TKey, TLessFunc, true>,
647 MemManagerStd<TAllocator>>>
648 class multiset :
public set<TKey, TLessFunc, TAllocator, TTreeSet>
692 template<
typename... ValueArgs>
695 return Set::emplace(std::forward<ValueArgs>(valueArgs)...).first;
698 template<
typename ValueFilter>
701 return cont.get_nested_container().Remove(valueFilter);
705 #ifdef MOMO_HAS_DEDUCTION_GUIDES
707 #define MOMO_DECLARE_DEDUCTION_GUIDES(set) \
708 template<typename Iterator, \
709 typename Key = typename std::iterator_traits<Iterator>::value_type, \
710 typename Allocator = std::allocator<Key>, \
711 typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
712 set(Iterator, Iterator, Allocator = Allocator()) \
713 -> set<Key, std::less<Key>, Allocator>; \
714 template<typename Iterator, typename LessFunc, \
715 typename Key = typename std::iterator_traits<Iterator>::value_type, \
716 typename Allocator = std::allocator<Key>, \
717 typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
718 set(Iterator, Iterator, LessFunc, Allocator = Allocator()) \
719 -> set<Key, LessFunc, Allocator>; \
720 template<typename Key, \
721 typename Allocator = std::allocator<Key>, \
722 typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
723 set(std::initializer_list<Key>, Allocator = Allocator()) \
724 -> set<Key, std::less<Key>, Allocator>; \
725 template<typename Key, typename LessFunc, \
726 typename Allocator = std::allocator<Key>, \
727 typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
728 set(std::initializer_list<Key>, LessFunc, Allocator = Allocator()) \
729 -> set<Key, LessFunc, Allocator>;
731 MOMO_DECLARE_DEDUCTION_GUIDES(set)
732 MOMO_DECLARE_DEDUCTION_GUIDES(multiset)
734 #undef MOMO_DECLARE_DEDUCTION_GUIDES
736 #endif // MOMO_HAS_DEDUCTION_GUIDES
742 #endif // MOMO_INCLUDE_GUARD_STDISH_SET