14 #ifndef WPIUTIL_WPI_SMALLSET_H 15 #define WPIUTIL_WPI_SMALLSET_H 18 #include "wpi/SmallPtrSet.h" 19 #include "wpi/SmallVector.h" 20 #include "wpi/Compiler.h" 35 template <
typename T,
unsigned N,
typename C = std::less<T>>
43 using VIterator =
typename SmallVector<T, N>::const_iterator;
44 using mutable_iterator =
typename SmallVector<T, N>::iterator;
49 static_assert(N <= 32,
"N should be small");
52 using size_type = size_t;
56 LLVM_NODISCARD
bool empty()
const {
57 return Vector.empty() && Set.empty();
60 size_type size()
const {
61 return isSmall() ? Vector.size() : Set.size();
65 size_type
count(
const T &V)
const {
68 return vfind(V) == Vector.end() ? 0 : 1;
81 std::pair<NoneType, bool>
insert(
const T &V) {
83 return std::make_pair(None, Set.insert(V).second);
85 VIterator I = vfind(V);
86 if (I != Vector.end())
87 return std::make_pair(None,
false);
88 if (Vector.size() < N) {
90 return std::make_pair(None,
true);
94 while (!Vector.empty()) {
95 Set.insert(Vector.back());
99 return std::make_pair(None,
true);
102 template <
typename IterT>
103 void insert(IterT I, IterT E) {
108 bool erase(
const T &V) {
111 for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
125 bool isSmall()
const {
return Set.empty(); }
127 VIterator vfind(
const T &V)
const {
128 for (VIterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
137 template <
typename Po
inteeType,
unsigned N>
142 #endif // LLVM_ADT_SMALLSET_H This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:868
namespace to hold default to_json function
Definition: json_binary_writer.cpp:39
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:36
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:81
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:65