14 #ifndef LLVM_ADT_SMALLSET_H 15 #define LLVM_ADT_SMALLSET_H 17 #include "llvm/None.h" 18 #include "llvm/SmallPtrSet.h" 19 #include "llvm/SmallVector.h" 31 template <
typename T,
unsigned N,
typename C = std::less<T> >
38 typedef typename SmallVector<T, N>::const_iterator VIterator;
39 typedef typename SmallVector<T, N>::iterator mutable_iterator;
44 static_assert(N <= 32,
"N should be small");
47 typedef size_t size_type;
50 bool LLVM_ATTRIBUTE_UNUSED_RESULT empty()
const {
51 return Vector.empty() && Set.empty();
54 size_type size()
const {
55 return isSmall() ? Vector.size() : Set.size();
59 size_type
count(
const T &V)
const {
62 return vfind(V) == Vector.end() ? 0 : 1;
75 std::pair<NoneType, bool>
insert(
const T &V) {
77 return std::make_pair(None, Set.insert(V).second);
79 VIterator I = vfind(V);
80 if (I != Vector.end())
81 return std::make_pair(None,
false);
82 if (Vector.size() < N) {
84 return std::make_pair(None,
true);
88 while (!Vector.empty()) {
89 Set.insert(Vector.back());
93 return std::make_pair(None,
true);
96 template <
typename IterT>
97 void insert(IterT I, IterT E) {
102 bool erase(
const T &V) {
105 for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
119 bool isSmall()
const {
return Set.empty(); }
121 VIterator vfind(
const T &V)
const {
122 for (VIterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
131 template <
typename Po
inteeType,
unsigned N>
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:32
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:75
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:59
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:834