20#ifndef LLVM_ADT_SETVECTOR_H
21#define LLVM_ADT_SETVECTOR_H
57template <
typename T,
typename Vector = SmallVector<T, 0>,
58 typename Set = DenseSet<T>,
unsigned N = 0>
62 static_assert(
N <= 32,
"Small size should be less than or equal to 32!");
71 using iterator =
typename vector_type::const_iterator;
86 template <
typename Range>
95 return std::move(vector_);
100 return vector_.empty();
105 return vector_.size();
110 return vector_.begin();
115 return vector_.begin();
120 return vector_.end();
125 return vector_.end();
130 return vector_.rbegin();
135 return vector_.rbegin();
140 return vector_.rend();
145 return vector_.rend();
150 assert(!
empty() &&
"Cannot call front() on empty SetVector!");
151 return vector_.front();
156 assert(!
empty() &&
"Cannot call back() on empty SetVector!");
157 return vector_.back();
162 assert(n < vector_.size() &&
"SetVector access out of range!");
169 if constexpr (canBeSmall())
172 vector_.push_back(
X);
173 if (vector_.size() >
N)
180 bool result = set_.insert(
X).second;
182 vector_.push_back(
X);
187 template<
typename It>
189 for (; Start !=
End; ++Start)
199 if constexpr (canBeSmall())
201 typename vector_type::iterator
I =
find(vector_,
X);
202 if (
I != vector_.end()) {
210 typename vector_type::iterator
I =
find(vector_,
X);
211 assert(
I != vector_.end() &&
"Corrupted SetVector instances!");
223 if constexpr (canBeSmall())
225 return vector_.erase(
I);
228 assert(set_.count(V) &&
"Corrupted SetVector instances!");
230 return vector_.erase(
I);
246 template <
typename UnaryPredicate>
248 typename vector_type::iterator
I = [
this,
P] {
249 if constexpr (canBeSmall())
262 if (
I == vector_.end())
264 vector_.erase(
I, vector_.end());
270 if constexpr (canBeSmall())
274 return set_.find(key) != set_.end();
291 assert(!
empty() &&
"Cannot remove an element from an empty SetVector!");
303 return vector_ == that.vector_;
307 return vector_ != that.vector_;
315 bool Changed =
false;
317 for (
const auto &Elem : S)
329 for (
const auto &Elem : S)
335 vector_.swap(
RHS.vector_);
339 [[nodiscard]]
static constexpr bool canBeSmall() {
return N != 0; }
341 [[nodiscard]]
bool isSmall()
const {
return set_.empty(); }
344 if constexpr (canBeSmall())
345 for (
const auto &entry : vector_)
355template <
typename T,
unsigned N>
366template <
typename T,
typename V,
typename S,
unsigned N>
373template<
typename T,
unsigned N>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseSet and SmallDenseSet classes.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains library features backported from future STL versions.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Implements a dense probed hash-table based set.
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.
void insert_range(Range &&R)
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.
SetVector(llvm::from_range_t, Range &&R)
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
auto remove_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::remove_if 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.