LLVM: llvm::SparseMultiSet< ValueT, KeyT, KeyFunctorT, SparseT (original) (raw)

Fast multiset implementation for objects that can be identified by small unsigned keys. More...

#include "[llvm/ADT/SparseMultiSet.h](SparseMultiSet%5F8h%5Fsource.html)"

Classes
class iterator_base
Our iterators are iterators over the collection of objects that share a key. More...
Public Types
using value_type = ValueT
using reference = ValueT &
using const_reference = const ValueT &
using pointer = ValueT *
using const_pointer = const ValueT *
using size_type = unsigned
using iterator = iterator_base<SparseMultiSet *>
using const_iterator = iterator_base<const SparseMultiSet *>
using RangePair = std::pair<iterator, iterator>
Public Member Functions
SparseMultiSet ()=default
SparseMultiSet (const SparseMultiSet &)=delete
SparseMultiSet & operator= (const SparseMultiSet &)=delete
~SparseMultiSet ()
void setUniverse (unsigned U)
Set the universe size which determines the largest key the set can hold.
iterator end ()
Returns an iterator past this container.
const_iterator end () const
bool empty () const
Returns true if the set is empty.
size_type size () const
Returns the number of elements in the set.
void clear ()
Clears the set.
iterator findIndex (unsigned Idx)
Find an element by its index.
iterator find (const KeyT &Key)
Find an element by its key.
const_iterator find (const KeyT &Key) const
size_type count (const KeyT &Key) const
Returns the number of elements identified by Key.
bool contains (const KeyT &Key) const
Returns true if this set contains an element identified by Key.
iterator getHead (const KeyT &Key)
Return the head and tail of the subset's list, otherwise returns end().
iterator getTail (const KeyT &Key)
RangePair equal_range (const KeyT &K)
The bounds of the range of items sharing Key K.
iterator insert (const ValueT &Val)
Insert a new element at the tail of the subset list.
iterator erase (iterator I)
Erases an existing element identified by a valid iterator.
void eraseAll (const KeyT &K)
Erase all elements with the given key.

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>
class llvm::SparseMultiSet< ValueT, KeyT, KeyFunctorT, SparseT >

Fast multiset implementation for objects that can be identified by small unsigned keys.

SparseMultiSet 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, SparseMultiSet provides constant-time fast clear() 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. Iteration order is the insertion order. Iteration is only provided over elements of equivalent keys, but iterators are bidirectional.

Compared to BitVector, SparseMultiSet 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.

SparseMultiSet 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 up to 3 cache lines, but the sparse array uses 4 x Universe bytes.

When SparseT is uint8_t (the default), find() touches up to 3+[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.

Multiset behavior is provided by providing doubly linked lists for values that are inlined in the dense vector. SparseMultiSet is a good choice when one desires a growable number of entries per key, as it will retain the SparseSet algorithmic properties despite being growable. Thus, it is often a better choice than a SparseSet of growable containers or a vector of vectors. SparseMultiSet also keeps iterators valid after erasure (provided the iterators don't point to the element erased), allowing for more intuitive and fast removal.

Template Parameters

ValueT The type of objects in the set.
KeyT The type of the key that identifies objects in the set.
KeyFunctorT A functor that computes an unsigned index from KeyT.
SparseT An unsigned integer type. See above.

Definition at line 86 of file SparseMultiSet.h.

const_iterator

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

const_pointer

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

const_reference

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

iterator

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

pointer

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

RangePair

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

reference

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

size_type

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

value_type

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

SparseMultiSet() [2/2]

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

~SparseMultiSet()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

clear()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Clears the set.

This is a very fast constant time operation.

Definition at line 335 of file SparseMultiSet.h.

contains()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Returns true if this set contains an element identified by Key.

Definition at line 386 of file SparseMultiSet.h.

count()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Returns the number of elements identified by Key.

This will be linear in the number of elements of that key.

Definition at line 377 of file SparseMultiSet.h.

empty()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

end() [1/2]

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Returns an iterator past this container.

Note that such an iterator cannot be decremented, but will compare equal to other end iterators.

Definition at line 312 of file SparseMultiSet.h.

Referenced by llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::contains(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::count(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::eraseAll(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::findIndex(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::getTail(), and llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::insert().

end() [2/2]

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

equal_range()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

The bounds of the range of items sharing Key K.

First member is the head of the list, and the second member is a decrementable end iterator for that key.

Definition at line 400 of file SparseMultiSet.h.

erase()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Erases an existing element identified by a valid iterator.

This invalidates iterators pointing at the same entry, but erase() returns an iterator pointing to the next element in the subset's list. This makes it possible to erase selected elements while iterating over the subset:

tie(I, E) = Set.equal_range(Key); while (I != E) if (test(*I)) I = Set.erase(I); else ++I;

Note that if the last element in the subset list is erased, this will return an end iterator which can be decremented to get the new tail (if it exists):

tie(B, I) = Set.equal_range(Key); for (bool isBegin = B == I; !isBegin; /* empty *‍/) { isBegin = (–I) == B; if (test(I)) break; I = erase(I); }

Definition at line 455 of file SparseMultiSet.h.

Referenced by llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::eraseAll().

eraseAll()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Erase all elements with the given key.

This invalidates all iterators of that key.

Definition at line 471 of file SparseMultiSet.h.

find() [1/2]

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Find an element by its key.

Parameters

Returns

An iterator to the element identified by key, or end().

Definition at line 368 of file SparseMultiSet.h.

Referenced by llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::contains(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::count(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::equal_range(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::eraseAll(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::getHead(), and llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::getTail().

find() [2/2]

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

findIndex()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Find an element by its index.

Parameters

Idx A valid index to find.

Returns

An iterator to the element identified by key, or end().

Definition at line 347 of file SparseMultiSet.h.

Referenced by llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::find(), llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::find(), and llvm::SparseMultiSet< PhysRegSUOper, MCRegUnit, MCRegUnitToIndex, uint16_t >::insert().

getHead()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Return the head and tail of the subset's list, otherwise returns end().

Definition at line 389 of file SparseMultiSet.h.

getTail()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

insert()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Insert a new element at the tail of the subset list.

Returns an iterator to the newly added entry.

Definition at line 408 of file SparseMultiSet.h.

operator=()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

setUniverse()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>

Set the universe size which determines the largest key the set can hold.

The universe must be sized before any elements can be added.

Parameters

U Universe size. All object keys must be less than U.

Definition at line 197 of file SparseMultiSet.h.

size()

template<typename ValueT, typename KeyT = unsigned, typename KeyFunctorT = identity, typename SparseT = uint8_t>


The documentation for this class was generated from the following file: