LLVM
8.0.1
|
SparseSet - Fast set implmentation for objects that can be identified by small unsigned keys. More...
#include "llvm/ADT/SparseSet.h"
Public Types | |
using | value_type = ValueT |
using | reference = ValueT & |
using | const_reference = const ValueT & |
using | pointer = ValueT * |
using | const_pointer = const ValueT * |
using | iterator = typename DenseT::iterator |
using | const_iterator = typename DenseT::const_iterator |
Public Member Functions | |
SparseSet ()=default | |
SparseSet (const SparseSet &)=delete | |
SparseSet & | operator= (const SparseSet &)=delete |
~SparseSet () | |
void | setUniverse (unsigned U) |
setUniverse - Set the universe size which determines the largest key the set can hold. More... | |
const_iterator | begin () const |
const_iterator | end () const |
iterator | begin () |
iterator | end () |
bool | empty () const |
empty - Returns true if the set is empty. More... | |
size_type | size () const |
size - Returns the number of elements in the set. More... | |
void | clear () |
clear - Clears the set. More... | |
iterator | findIndex (unsigned Idx) |
findIndex - Find an element by its index. More... | |
iterator | find (const KeyT &Key) |
find - Find an element by its key. More... | |
const_iterator | find (const KeyT &Key) const |
size_type | count (const KeyT &Key) const |
count - Returns 1 if this set contains an element identified by Key, 0 otherwise. More... | |
std::pair< iterator, bool > | insert (const ValueT &Val) |
insert - Attempts to insert a new element. More... | |
ValueT & | operator[] (const KeyT &Key) |
array subscript - If an element already exists with this key, return it. More... | |
ValueT | pop_back_val () |
iterator | erase (iterator I) |
erase - Erases an existing element identified by a valid iterator. More... | |
bool | erase (const KeyT &Key) |
erase - Erases an element identified by Key, if it exists. More... | |
SparseSet - Fast set implmentation for objects that can be identified by small unsigned keys.
SparseSet allocates memory proportional to the size of the key universe, so it is not recommended for building composite data structures. It is useful for algorithms that require a single set with fast operations.
Compared to DenseSet and DenseMap, SparseSet provides constant-time fast clear() and iteration as fast as a vector. The find(), insert(), and erase() operations are all constant time, and typically faster than a hash table. The iteration order doesn't depend on numerical key values, it only depends on the order of insert() and erase() operations. When no elements have been erased, the iteration order is the insertion order.
Compared to BitVector, SparseSet<unsigned> uses 8x-40x more memory, but offers constant-time clear() and size() operations as well as fast iteration independent on the size of the universe.
SparseSet contains a dense vector holding all the objects and a sparse array holding indexes into the dense vector. Most of the memory is used by the sparse array which is the size of the key universe. The SparseT template parameter provides a space/speed tradeoff for sets holding many elements.
When SparseT is uint32_t, find() only touches 2 cache lines, but the sparse array uses 4 x Universe bytes.
When SparseT is uint8_t (the default), find() touches up to 2+[N/256] cache lines, but the sparse array is 4x smaller. N is the number of elements in the set.
For sets that may grow to thousands of elements, SparseT should be set to uint16_t or uint32_t.
ValueT | The type of objects in the set. |
KeyFunctorT | A functor that computes an unsigned index from KeyT. |
SparseT | An unsigned integer type. See above. |
Definition at line 124 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::const_iterator = typename DenseT::const_iterator |
Definition at line 173 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::const_pointer = const ValueT * |
Definition at line 143 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::const_reference = const ValueT & |
Definition at line 141 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::iterator = typename DenseT::iterator |
Definition at line 172 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::pointer = ValueT * |
Definition at line 142 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::reference = ValueT & |
Definition at line 140 of file SparseSet.h.
using llvm::SparseSet< ValueT, KeyFunctorT, SparseT >::value_type = ValueT |
Definition at line 139 of file SparseSet.h.
|
default |
|
delete |
|
inline |
Definition at line 148 of file SparseSet.h.
|
inline |
Definition at line 175 of file SparseSet.h.
Referenced by llvm::LivePhysRegs::begin(), insertDeleteInstructions(), pushDepHeight(), and llvm::LivePhysRegs::removeRegsInMask().
|
inline |
Definition at line 177 of file SparseSet.h.
|
inline |
clear - Clears the set.
This is a very fast constant time operation.
Definition at line 195 of file SparseSet.h.
Referenced by llvm::LivePhysRegs::clear(), and llvm::LivePhysRegs::init().
|
inline |
count - Returns 1 if this set contains an element identified by Key, 0 otherwise.
Definition at line 236 of file SparseSet.h.
Referenced by llvm::LivePhysRegs::available(), llvm::LivePhysRegs::contains(), llvm::RegPressureTracker::hasUntiedDef(), UpdatePredRedefs(), and llvm::SchedDFSImpl::visitPostorderNode().
|
inline |
empty - Returns true if the set is empty.
This is not the same as BitVector::empty().
Definition at line 184 of file SparseSet.h.
Referenced by llvm::LivePhysRegs::empty().
|
inline |
Definition at line 176 of file SparseSet.h.
Referenced by llvm::LiveRegSet::contains(), llvm::LivePhysRegs::end(), llvm::LiveRegSet::erase(), insertDeleteInstructions(), pushDepHeight(), llvm::LivePhysRegs::removeRegsInMask(), updatePhysDepsDownwards(), and updatePhysDepsUpwards().
|
inline |
Definition at line 178 of file SparseSet.h.
|
inline |
erase - Erases an existing element identified by a valid iterator.
This invalidates all iterators, but erase() returns an iterator pointing to the next element. This makes it possible to erase selected elements while iterating over the set:
for (SparseSet::iterator I = Set.begin(); I != Set.end();) if (test(*I)) I = Set.erase(I); else ++I;
Note that end() changes when elements are erased, unlike std::list.
Definition at line 286 of file SparseSet.h.
Referenced by insertDeleteInstructions(), llvm::LivePhysRegs::removeReg(), llvm::LivePhysRegs::removeRegsInMask(), updatePhysDepsDownwards(), updatePhysDepsUpwards(), and llvm::SchedDFSImpl::visitPostorderNode().
|
inline |
erase - Erases an element identified by Key, if it exists.
Key | The key identifying the element to erase. |
Definition at line 305 of file SparseSet.h.
|
inline |
find - Find an element by its key.
Key | A valid key to find. |
Definition at line 225 of file SparseSet.h.
Referenced by llvm::LiveRegSet::contains(), llvm::LiveRegSet::erase(), updatePhysDepsDownwards(), and updatePhysDepsUpwards().
|
inline |
Definition at line 229 of file SparseSet.h.
|
inline |
findIndex - Find an element by its index.
Idx | A valid index to find. |
Definition at line 205 of file SparseSet.h.
|
inline |
insert - Attempts to insert a new element.
If Val is successfully inserted, return (I, true), where I is an iterator pointing to the newly inserted element.
If the set already contains an element with the same key as Val, return (I, false), where I is an iterator pointing to the existing element.
Insertion invalidates all iterators.
Definition at line 250 of file SparseSet.h.
Referenced by llvm::LivePhysRegs::addReg(), llvm::SpillPlacement::Node::getDissentingNeighbors(), llvm::LiveRegSet::insert(), and UpdatePredRedefs().
|
delete |
|
inline |
array subscript - If an element already exists with this key, return it.
Otherwise, automatically construct a new value from Key, insert it, and return the newly inserted element.
Definition at line 263 of file SparseSet.h.
|
inline |
Definition at line 267 of file SparseSet.h.
|
inline |
setUniverse - Set the universe size which determines the largest key the set can hold.
The universe must be sized before any elements can be added.
U | Universe size. All object keys must be less than U. |
Definition at line 156 of file SparseSet.h.
Referenced by llvm::LivePhysRegs::init(), insertDeleteInstructions(), llvm::LivePhysRegs::LivePhysRegs(), pushDepHeight(), llvm::SchedDFSImpl::SchedDFSImpl(), and UpdatePredRedefs().
|
inline |
size - Returns the number of elements in the set.
This is not the same as BitVector::size() which returns the size of the universe.
Definition at line 191 of file SparseSet.h.
Referenced by llvm::SchedDFSImpl::finalize(), and llvm::LiveRegSet::size().