20 #ifndef LLVM_ADT_SPARSESET_H
21 #define LLVM_ADT_SPARSESET_H
25 #include "llvm/Support/DataTypes.h"
52 template<
typename ValueT>
55 return Val.getSparseSetIndex();
63 template<
typename KeyT,
typename ValueT,
typename KeyFunctorT>
72 template<
typename KeyT,
typename KeyFunctorT>
75 return KeyFunctorT()(Key);
117 template<
typename ValueT,
119 typename SparseT = uint8_t>
121 typedef typename KeyFunctorT::argument_type KeyT;
126 KeyFunctorT KeyIndexOf;
153 assert(
empty() &&
"Can only resize universe on an empty map");
155 if (U >= Universe/4 && U <= Universe)
161 Sparse =
reinterpret_cast<SparseT*
>(
calloc(U,
sizeof(SparseT)));
200 assert(Idx < Universe &&
"Key out of range");
201 assert(std::numeric_limits<SparseT>::is_integer &&
202 !std::numeric_limits<SparseT>::is_signed &&
203 "SparseT must be an unsigned integer type");
204 const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
205 for (
unsigned i = Sparse[Idx], e =
size(); i < e; i += Stride) {
206 const unsigned FoundIdx = ValIndexOf(Dense[i]);
207 assert(FoundIdx < Universe &&
"Invalid key in set. Did object mutate?");
246 std::pair<iterator, bool>
insert(
const ValueT &Val) {
247 unsigned Idx = ValIndexOf(Val);
250 return std::make_pair(I,
false);
251 Sparse[Idx] =
size();
253 return std::make_pair(
end() - 1,
true);
260 return *
insert(ValueT(Key)).first;
278 assert(
unsigned(I -
begin()) <
size() &&
"Invalid iterator");
279 if (I !=
end() - 1) {
281 unsigned BackIdx = ValIndexOf(Dense.
back());
282 assert(BackIdx < Universe &&
"Invalid key in set. Did object mutate?");
283 Sparse[BackIdx] = I -
begin();
ValueT & operator[](const KeyT &Key)
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)
bool erase(const KeyT &Key)
const ValueT & const_reference
const_iterator end() const
const_iterator find(const KeyT &Key) const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
iterator findIndex(unsigned Idx)
DenseT::iterator iterator
iterator erase(iterator I)
void setUniverse(unsigned U)
const_iterator begin() const
bool count(const KeyT &Key) const
#define LLVM_DELETED_FUNCTION
const ValueT * const_pointer
iterator find(const KeyT &Key)
unsigned operator()(const KeyT &Key) const
void *calloc(size_t count, size_t size);
static unsigned getValIndex(const ValueT &Val)