20#ifndef LLVM_ADT_SETVECTOR_H
21#define LLVM_ADT_SETVECTOR_H
55template <
typename T,
typename Vector = SmallVector<T, 0>,
56 typename Set = DenseSet<T>,
unsigned N = 0>
60 static_assert(
N <= 32,
"Small size should be less than or equal to 32!");
69 using iterator =
typename vector_type::const_iterator;
89 return std::move(vector_);
94 return vector_.empty();
99 return vector_.size();
104 return vector_.begin();
109 return vector_.begin();
114 return vector_.end();
119 return vector_.end();
124 return vector_.rbegin();
129 return vector_.rbegin();
134 return vector_.rend();
139 return vector_.rend();
144 assert(!
empty() &&
"Cannot call front() on empty SetVector!");
145 return vector_.front();
150 assert(!
empty() &&
"Cannot call back() on empty SetVector!");
151 return vector_.back();
156 assert(n < vector_.size() &&
"SetVector access out of range!");
163 if constexpr (canBeSmall())
166 vector_.push_back(
X);
167 if (vector_.size() >
N)
174 bool result = set_.insert(
X).second;
176 vector_.push_back(
X);
181 template<
typename It>
183 for (; Start !=
End; ++Start)
189 if constexpr (canBeSmall())
191 typename vector_type::iterator
I =
find(vector_,
X);
192 if (
I != vector_.end()) {
200 typename vector_type::iterator
I =
find(vector_,
X);
201 assert(
I != vector_.end() &&
"Corrupted SetVector instances!");
213 if constexpr (canBeSmall())
215 return vector_.erase(
I);
218 assert(set_.count(V) &&
"Corrupted SetVector instances!");
220 return vector_.erase(
I);
236 template <
typename UnaryPredicate>
238 typename vector_type::iterator
I = [
this,
P] {
239 if constexpr (canBeSmall())
244 TestAndEraseFromSet<UnaryPredicate>(
P, set_));
247 if (
I == vector_.end())
249 vector_.erase(
I, vector_.end());
255 if constexpr (canBeSmall())
259 return set_.find(key) != set_.end();
265 if constexpr (canBeSmall())
269 return set_.count(key);
280 assert(!
empty() &&
"Cannot remove an element from an empty SetVector!");
292 return vector_ == that.vector_;
296 return vector_ != that.vector_;
304 bool Changed =
false;
306 for (
typename STy::const_iterator SI = S.begin(), SE = S.end(); SI != SE;
319 for (
typename STy::const_iterator SI = S.begin(), SE = S.end(); SI != SE;
326 vector_.swap(
RHS.vector_);
334 template <
typename UnaryPredicate>
335 class TestAndEraseFromSet {
340 TestAndEraseFromSet(UnaryPredicate P,
set_type &set_)
343 template <
typename ArgumentT>
344 bool operator()(
const ArgumentT &Arg) {
353 [[nodiscard]]
static constexpr bool canBeSmall() {
return N != 0; }
355 [[nodiscard]]
bool isSmall()
const {
return set_.empty(); }
358 if constexpr (canBeSmall())
359 for (
const auto &entry : vector_)
369template <
typename T,
unsigned N>
375 template<
typename It>
386template <
typename T,
typename V,
typename S,
unsigned N>
393template<
typename T,
unsigned N>
This file defines the DenseSet and SmallDenseSet classes.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A vector that has set insertion semantics.
const_reverse_iterator rend() const
Get a const_reverse_iterator to the beginning of the SetVector.
ArrayRef< value_type > getArrayRef() const
typename vector_type::const_reverse_iterator reverse_iterator
iterator erase(const_iterator I)
Erase a single element from the set vector.
bool remove(const value_type &X)
Remove an item from the set vector.
bool remove_if(UnaryPredicate P)
Remove items from the set vector based on a predicate function.
size_type size() const
Determine the number of elements in the SetVector.
const value_type & front() const
Return the first element of the SetVector.
bool operator==(const SetVector &that) const
typename vector_type::const_reverse_iterator const_reverse_iterator
const value_type & back() const
Return the last element of the SetVector.
bool set_union(const STy &S)
Compute This := This u S, return whether 'This' changed.
typename Vector::value_type value_type
const_reverse_iterator rbegin() const
Get a const_reverse_iterator to the end of the SetVector.
Vector takeVector()
Clear the SetVector and return the underlying vector.
typename vector_type::const_iterator iterator
iterator end()
Get an iterator to the end of the SetVector.
SetVector()=default
Construct an empty SetVector.
reverse_iterator rbegin()
Get an reverse_iterator to the end of the SetVector.
typename vector_type::const_iterator const_iterator
const_iterator end() const
Get a const_iterator to the end of the SetVector.
void clear()
Completely clear the SetVector.
bool operator!=(const SetVector &that) const
reverse_iterator rend()
Get a reverse_iterator to the beginning of the SetVector.
typename vector_type::size_type size_type
const_iterator begin() const
Get a const_iterator to the beginning of the SetVector.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
void insert(It Start, It End)
Insert a range of elements into the SetVector.
const value_type & const_reference
iterator begin()
Get an iterator to the beginning of the SetVector.
SetVector(It Start, It End)
Initialize a SetVector with a range of elements.
void swap(SetVector< T, Vector, Set, N > &RHS)
typename Set::key_type key_type
void set_subtract(const STy &S)
Compute This := This - B TODO: We should be able to use set_subtract from SetOperations....
bool insert(const value_type &X)
Insert a new element into the SetVector.
void pop_back()
Remove the last element of the SetVector.
value_type pop_back_val()
const_reference operator[](size_type n) const
Index into the SetVector.
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
A SetVector that performs no allocations if smaller than a certain size.
SmallSetVector(It Start, It End)
Initialize a SmallSetVector with a range of elements.
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
auto remove_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.