14#ifndef WPIUTIL_WPI_SMALLSET_H
15#define WPIUTIL_WPI_SMALLSET_H
22#include <initializer_list>
30template <
typename T,
unsigned N,
typename C>
33 std::forward_iterator_tag, T> {
35 using SetIterTy =
typename std::set<T, C>::const_iterator;
73 VecIter = std::move(Other.VecIter);
77 new (&
SetIter) SetIterTy(std::move(Other.SetIter));
86 IsSmall = Other.IsSmall;
100 IsSmall = Other.IsSmall;
102 VecIter = std::move(Other.VecIter);
104 new (&
SetIter) SetIterTy(std::move(Other.SetIter));
109 if (IsSmall != RHS.IsSmall)
131template <
typename T,
unsigned N,
typename C = std::less<T>>
142 static_assert(N <= 32,
"N should be small");
154 template <
typename IterT>
SmallSet(IterT Begin, IterT End) {
158 template <
typename RangeT>
168 [[nodiscard]]
bool empty()
const {
return Vector.
empty() && Set.empty(); }
171 return isSmall() ? Vector.
size() : Set.size();
181 std::pair<const_iterator, bool>
insert(
const T &V) {
return insertImpl(V); }
183 std::pair<const_iterator, bool>
insert(T &&V) {
184 return insertImpl(std::move(V));
187 template <
typename IterT>
197 if (I != Vector.
end()) {
211 return {Vector.
begin()};
212 return {Set.begin()};
217 return {Vector.
end()};
224 return vfind(V) != Vector.
end();
225 return Set.find(V) != Set.end();
229 bool isSmall()
const {
return Set.empty(); }
231 template <
typename ArgType>
232 std::pair<const_iterator, bool> insertImpl(ArgType &&V) {
233 static_assert(std::is_convertible_v<ArgType, T>,
234 "ArgType must be convertible to T!");
236 auto [I, Inserted] = Set.insert(std::forward<ArgType>(V));
241 if (I != Vector.
end())
243 if (Vector.
size() < N) {
244 Vector.
push_back(std::forward<ArgType>(V));
248 Set.insert(std::make_move_iterator(Vector.
begin()),
249 std::make_move_iterator(Vector.
end()));
251 return {
const_iterator(Set.insert(std::forward<ArgType>(V)).first),
true};
257 for (
auto I = Vector.
begin(), E = Vector.
end(); I != E; ++I)
266template <
typename Po
inteeType,
unsigned N>
277template <
typename T,
unsigned LN,
unsigned RN,
typename C>
283 return std::all_of(LHS.
begin(), LHS.
end(), [&RHS](
const T &E) { return RHS.count(E); });
289template <
typename T,
unsigned LN,
unsigned RN,
typename C>
291 return !(LHS == RHS);
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition SmallPtrSet.h:519
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:132
T value_type
Definition SmallSet.h:147
T key_type
Definition SmallSet.h:145
bool erase(const T &V)
Definition SmallSet.h:193
const_iterator end() const
Definition SmallSet.h:215
size_t size_type
Definition SmallSet.h:146
SmallSet(std::initializer_list< T > L)
Definition SmallSet.h:163
void insert(IterT I, IterT E)
Definition SmallSet.h:188
SmallSet(const iterator_range< RangeT > &R)
Definition SmallSet.h:159
bool contains(const T &V) const
Check if the SmallSet contains the given element.
Definition SmallSet.h:222
SmallSet(IterT Begin, IterT End)
Definition SmallSet.h:154
std::pair< const_iterator, bool > insert(T &&V)
Definition SmallSet.h:183
bool empty() const
Definition SmallSet.h:168
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition SmallSet.h:175
SmallSet & operator=(SmallSet &&)=default
SmallSet(const SmallSet &)=default
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:181
SmallSetIterator< T, N, C > const_iterator
Definition SmallSet.h:148
void clear()
Definition SmallSet.h:204
const_iterator begin() const
Definition SmallSet.h:209
SmallSet & operator=(const SmallSet &)=default
size_type size() const
Definition SmallSet.h:170
SmallSet(SmallSet &&)=default
SmallSetIterator - This class implements a const_iterator for SmallSet by delegating to the underlyin...
Definition SmallSet.h:33
SmallSetIterator(const SmallSetIterator &Other)
Definition SmallSet.h:62
SmallSetIterator(SetIterTy SetIter)
Definition SmallSet.h:49
bool operator==(const SmallSetIterator &RHS) const
Definition SmallSet.h:108
SetIterTy SetIter
Definition SmallSet.h:42
SmallSetIterator(VecIterTy VecIter)
Definition SmallSet.h:51
~SmallSetIterator()
Definition SmallSet.h:55
const T & operator*() const
Definition SmallSet.h:124
SmallSetIterator & operator++()
Definition SmallSet.h:116
SmallSetIterator & operator=(const SmallSetIterator &Other)
Definition SmallSet.h:80
VecIterTy VecIter
Definition SmallSet.h:43
SmallSetIterator(SmallSetIterator &&Other)
Definition SmallSet.h:71
SmallSetIterator & operator=(SmallSetIterator &&Other)
Definition SmallSet.h:94
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition SmallVector.h:1198
iterator erase(const_iterator CI)
Definition SmallVector.h:739
void clear()
Definition SmallVector.h:612
void push_back(const T &Elt)
Definition SmallVector.h:415
size_t size() const
Definition SmallVector.h:85
iterator begin()
Definition SmallVector.h:269
iterator end()
Definition SmallVector.h:271
const T * const_iterator
Definition SmallVector.h:254
bool empty() const
Definition SmallVector.h:88
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterator.h:80
A range adaptor for a pair of iterators.
Definition iterator_range.h:42
IteratorT end() const
Definition iterator_range.h:65
IteratorT begin() const
Definition iterator_range.h:64
Definition ntcore_cpp.h:26
bool operator==(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Equality comparison for DenseMap.
Definition DenseMap.h:698
bool operator!=(const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &LHS, const DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT > &RHS)
Inequality comparison for DenseMap.
Definition DenseMap.h:718