20 #ifndef LLVM_ADT_SPARSESET_H
21 #define LLVM_ADT_SPARSESET_H
55 template<
typename ValueT>
58 return Val.getSparseSetIndex();
66 template<
typename KeyT,
typename ValueT,
typename KeyFunctorT>
75 template<
typename KeyT,
typename KeyFunctorT>
78 return KeyFunctorT()(Key);
121 typename KeyFunctorT = identity<unsigned>,
122 typename SparseT = uint8_t>
124 static_assert(std::numeric_limits<SparseT>::is_integer &&
125 !std::numeric_limits<SparseT>::is_signed,
126 "SparseT must be an unsigned integer type");
128 typedef typename KeyFunctorT::argument_type KeyT;
132 SparseT *Sparse =
nullptr;
133 unsigned Universe = 0;
134 KeyFunctorT KeyIndexOf;
158 assert(
empty() &&
"Can only resize universe on an empty map");
160 if (U >= Universe/4 && U <= Universe)
166 Sparse =
reinterpret_cast<SparseT*
>(calloc(U,
sizeof(SparseT)));
205 assert(Idx < Universe &&
"Key out of range");
206 const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
207 for (
unsigned i = Sparse[Idx], e =
size();
i < e;
i += Stride) {
208 const unsigned FoundIdx = ValIndexOf(Dense[
i]);
209 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
236 return find(Key) ==
end() ? 0 : 1;
250 unsigned Idx = ValIndexOf(Val);
253 return std::make_pair(I,
false);
254 Sparse[Idx] =
size();
256 return std::make_pair(
end() - 1,
true);
287 if (I !=
end() - 1) {
289 unsigned BackIdx = ValIndexOf(Dense.
back());
290 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
291 Sparse[BackIdx] = I -
begin();
315 #endif // LLVM_ADT_SPARSESET_H
ValueT & operator[](const KeyT &Key)
array subscript - If an element already exists with this key, return it.
void push_back(const T &Elt)
unsigned operator()(const ValueT &Val) const
DenseT::const_iterator const_iterator
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
bool erase(const KeyT &Key)
erase - Erases an element identified by Key, if it exists.
const ValueT & const_reference
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise. ...
SparseSetValTraits - Objects in a SparseSet are identified by keys that can be uniquely converted to ...
bool empty() const
empty - Returns true if the set is empty.
const_iterator end() const
const_iterator find(const KeyT &Key) const
LLVM_NODISCARD bool empty() const
iterator findIndex(unsigned Idx)
findIndex - Find an element by its index.
DenseT::iterator iterator
iterator erase(iterator I)
erase - Erases an existing element identified by a valid iterator.
size_type size() const
size - Returns the number of elements in the set.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
const_iterator begin() const
SparseSet & operator=(const SparseSet &)=delete
LLVM_NODISCARD T pop_back_val()
const ValueT * const_pointer
SparseSetValFunctor - Helper class for selecting SparseSetValTraits.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
SparseSet - Fast set implmentation for objects that can be identified by small unsigned keys...
iterator find(const KeyT &Key)
find - Find an element by its key.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void clear()
clear - Clears the set.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned operator()(const KeyT &Key) const
static unsigned getValIndex(const ValueT &Val)