14#ifndef WPIUTIL_WPI_SMALLSET_H
15#define WPIUTIL_WPI_SMALLSET_H
33template <
typename T,
unsigned N,
typename C>
36 std::forward_iterator_tag, T> {
38 using SetIterTy =
typename std::set<T, C>::const_iterator;
76 VecIter = std::move(Other.VecIter);
80 new (&
SetIter) SetIterTy(std::move(Other.SetIter));
89 isSmall = Other.isSmall;
103 isSmall = Other.isSmall;
105 VecIter = std::move(Other.VecIter);
107 new (&
SetIter) SetIterTy(std::move(Other.SetIter));
112 if (isSmall != RHS.isSmall)
134template <
typename T,
unsigned N,
typename C = std::less<T>>
148 static_assert(N <= 32,
"N should be small");
157 return Vector.
empty() && Set.empty();
161 return isSmall() ? Vector.
size() : Set.size();
168 return vfind(V) == Vector.
end() ? 0 : 1;
181 std::pair<std::nullopt_t, bool>
insert(
const T &V) {
183 return std::make_pair(std::nullopt, Set.insert(V).second);
185 VIterator I = vfind(V);
186 if (I != Vector.
end())
187 return std::make_pair(std::nullopt,
false);
188 if (Vector.
size() < N) {
190 return std::make_pair(std::nullopt,
true);
194 while (!Vector.
empty()) {
195 Set.insert(Vector.
back());
199 return std::make_pair(std::nullopt,
true);
202 template <
typename IterT>
211 for (mutable_iterator I = Vector.
begin(), E = Vector.
end(); I != E; ++I)
226 return {Vector.
begin()};
227 return {Set.begin()};
232 return {Vector.
end()};
239 return vfind(V) != Vector.
end();
240 return Set.find(V) != Set.end();
244 bool isSmall()
const {
return Set.empty(); }
246 VIterator vfind(
const T &V)
const {
247 for (VIterator I = Vector.
begin(), E = Vector.
end(); I != E; ++I)
256template <
typename Po
inteeType,
unsigned N>
267template <
typename T,
unsigned LN,
unsigned RN,
typename C>
273 return std::all_of(LHS.
begin(), LHS.
end(), [&RHS](
const T &E) { return RHS.count(E); });
279template <
typename T,
unsigned LN,
unsigned RN,
typename C>
281 return !(LHS == RHS);
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
Definition: Compiler.h:177
This file defines the SmallPtrSet class.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
bool erase(const T &V)
Definition: SmallSet.h:208
const_iterator end() const
Definition: SmallSet.h:230
std::pair< std::nullopt_t, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:181
size_t size_type
Definition: SmallSet.h:151
void insert(IterT I, IterT E)
Definition: SmallSet.h:203
bool contains(const T &V) const
Check if the SmallSet contains the given element.
Definition: SmallSet.h:237
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:165
LLVM_NODISCARD bool empty() const
Definition: SmallSet.h:156
void clear()
Definition: SmallSet.h:219
const_iterator begin() const
Definition: SmallSet.h:224
size_type size() const
Definition: SmallSet.h:160
SmallSetIterator - This class implements a const_iterator for SmallSet by delegating to the underlyin...
Definition: SmallSet.h:36
SmallSetIterator(const SmallSetIterator &Other)
Definition: SmallSet.h:65
SmallSetIterator(SetIterTy SetIter)
Definition: SmallSet.h:52
bool operator==(const SmallSetIterator &RHS) const
Definition: SmallSet.h:111
SetIterTy SetIter
Definition: SmallSet.h:45
SmallSetIterator(VecIterTy VecIter)
Definition: SmallSet.h:54
~SmallSetIterator()
Definition: SmallSet.h:58
const T & operator*() const
Definition: SmallSet.h:127
SmallSetIterator & operator++()
Definition: SmallSet.h:119
SmallSetIterator & operator=(const SmallSetIterator &Other)
Definition: SmallSet.h:83
VecIterTy VecIter
Definition: SmallSet.h:46
SmallSetIterator(SmallSetIterator &&Other)
Definition: SmallSet.h:74
SmallSetIterator & operator=(SmallSetIterator &&Other)
Definition: SmallSet.h:97
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1186
iterator erase(const_iterator CI)
Definition: SmallVector.h:727
void clear()
Definition: SmallVector.h:594
void pop_back()
Definition: SmallVector.h:415
void push_back(const T &Elt)
Definition: SmallVector.h:403
size_t size() const
Definition: SmallVector.h:78
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:81
iterator begin()
Definition: SmallVector.h:252
iterator end()
Definition: SmallVector.h:254
reference back()
Definition: SmallVector.h:293
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
bool operator!=(PointerUnion< PTs... > lhs, PointerUnion< PTs... > rhs)
Definition: PointerUnion.h:244
bool operator==(PointerUnion< PTs... > lhs, PointerUnion< PTs... > rhs)
Definition: PointerUnion.h:239