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: SmallString.h:21
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:36
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:999
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:941