This template class is used to efficiently index objects. More...
Constructors and destructors | |
SBCContainerIndexer () | |
Creates an indexer. | |
SBCContainerIndexer (unsigned int initialSize) | |
Creates an indexer with a default pre-allocated size. | |
SBCContainerIndexer (std::set< ObjectType > &objectSet) | |
Indexes a set of objects. | |
SBCContainerIndexer (std::vector< ObjectType > &objectVector) | |
Indexes a vector of objects. | |
SBCContainerIndexer (const SBCContainerIndexer &indexer) | |
Creates a copy of indexer indexer . | |
virtual | ~SBCContainerIndexer () |
Destructs the indexer. | |
Operators | |
SBCContainerIndexer & | operator= (const SBCContainerIndexer &indexer) |
Assigns a copy of indexer indexer to this. | |
Indexing | |
void | clear () |
Clears the indexer. | |
unsigned int | push_back (const ObjectType &object) |
Adds an object in the indexer if possible, and returns the index of the object. | |
unsigned int | insert (unsigned int i, const ObjectType &object) |
Inserts an object in the indexer at position i if possible, and returns the index of the object. | |
unsigned int | pop_back () |
Adds an object in the indexer and returns the index of the object. | |
unsigned int | eraseObject (const ObjectType &object) |
Erases the object from the indexer. More... | |
unsigned int | eraseIndex (unsigned int objectIndex) |
Erases object objectIndex from the indexer. More... | |
bool | empty () const |
Returns true if and only if the indexer is empty. | |
unsigned int | size () const |
Returns the number of indexed objects. | |
bool | hasIndex (const ObjectType &object) const |
Returns true if the object has an index. | |
unsigned int | getIndex (const ObjectType &object) const |
Returns the index associated to the object. | |
bool | getIndex (const ObjectType &object, unsigned int &index) const |
Returns the index associated to the object. | |
ObjectType | getObject (unsigned int index) const |
Returns the object associated to the index. | |
ObjectType | operator[] (unsigned int index) const |
Returns the object associated to the index. | |
iterator | begin () |
Returns an iterator that points to the beginning of the indexer. | |
const_iterator | begin () const |
Returns an iterator that points to the beginning of the indexer. | |
iterator | end () |
Returns an iterator that points to the end of the indexer. | |
const_iterator | end () const |
Returns an iterator that points to the end of the indexer. | |
reverse_iterator | rbegin () |
Returns a reverse iterator that points to the reverse beginning of the indexer. | |
const_reverse_iterator | rbegin () const |
Returns a reverse iterator that points to the reverse beginning of the indexer. | |
reverse_iterator | rend () |
Returns a reverse iterator that points to the reverse end of the indexer. | |
const_reverse_iterator | rend () const |
Returns a reverse iterator that points to the reverse end of the indexer. | |
Debugging | |
void | print () const |
Prints some debugging information. | |
The hash table | |
HashMap * | indexMap |
The hash map. | |
Vector * | objectVector |
The object vector. | |
Fast indexing of objects is required in SAMSON because objects may operate on lists of other objects (e.g. a collision detection solver operates on a list of structural model components). An indexer provides a way to map the set of n
objects to a set of ordered indices, from 0
to n-1
, which can then be used for fast access to information associated to the mapped objects.
SBCContainerIndexer makes it possible to index values contiguously. Precisely, it is guaranteed that \(n\) values are always indexed by integers in \([0, n - 1]\). To achieve this, when an object with index \(i\neq n - 1\) is removed from the index, the index of object \(n - 1\) becomes \(i\). SBCContainerIndexer may be used to index values compactly and dynamically.
Internally, SBCContainerIndexer uses a hash map (by default SBCContainerHashMap) to assign indices and a vector (by default SBCContainerVector) to store objects. As a result, retrieving indices takes an almost constant time, while retrieving objects takes constant time.
Short name: SBIndexer
unsigned int SBCContainerIndexer< ObjectType, HashMap, Vector >::eraseIndex | ( | unsigned int | objectIndex | ) |
The function returns an unsigned int with the following meaning:
unsigned int SBCContainerIndexer< ObjectType, HashMap, Vector >::eraseObject | ( | const ObjectType & | object | ) |
The function returns an unsigned int with the following meaning: