A vector of objects with fast, space-efficient reverse lookup of array indices.
More...
|
| MarkedVector () |
| Constructs a new empty vector. More...
|
|
const std::vector< T * > & | operator() () const |
| Casts this vector to a const std::vector, thus providing access to the entire const functionality of std::vector. More...
|
|
void | push_back (T *item) |
| Pushes the given item onto the end of this vector. More...
|
|
std::vector< T * >::iterator | erase (typename std::vector< T *>::iterator pos) |
| Erases the item at the given position in this vector. More...
|
|
std::vector< T * >::iterator | erase (typename std::vector< T *>::iterator first, typename std::vector< T *>::iterator last) |
| Erases all items in the given range in this vector. More...
|
|
void | swap (MarkedVector< T > &other) |
| Swaps the contents of this and the given vector. More...
|
|
template<typename Iterator > |
void | refill (Iterator begin, Iterator end) |
| Empties this vector and refills it with the given range of items. More...
|
|
template<typename T>
class regina::MarkedVector< T >
A vector of objects with fast, space-efficient reverse lookup of array indices.
This class derives from std::vector, and so provides fast forward lookups from array indices to objects. What MarkedVector provides in addition to this is fast reverse lookups from objects back to array indices.
The way this class is able to provide fast constant-time reverse lookups without consuming a great deal of space is by storing array indices inside the objects themselves. As a result, there are two significant constraints:
- This class can only store objects derived from MarkedElement (which provides space for storing the array indices and handles their access control). In particular, it cannot store native types such as
int
or predefined types such as std::string
.
- An object can only belong to one MarkedVector at a time. Any attempt to insert an object into more than one MarkedVector at the same time results in undefined behaviour.
Using this class is fairly simple. The class provides a restricted subset of the std::vector functionality, including iterator, const_iterator, begin, end, size, empty, front, back, operator [], and clear (this subset may grow over time if required). In addition, any const method of std::vector can be accessed through an explicit cast to const std::vector&. To perform a reverse lookup (find the index at which an array is stored), simply call the object's inherited method MarkedElement::markedIndex().
Note that, like its parent std::vector, this class performs no memory management. In particular, elements (which are pointers to real objects) are not destroyed when they are removed from a vector or when the vector is eventually destroyed.
- Precondition
- The type T is a class derived from MarkedElement.
- Python:
- Not present.