template<typename>
class gmx::ListOfLists< typename >
A list of lists, optimized for performance.
This class holds a list of size()
lists of elements of type T
. To optimize performance, the only modification operation supporting is adding a new list at the end of the list of lists.
This implementation stores all data internally in two std::vector objects and thereby avoids the overhead of managing size()
separate objects in memory.
Internal storage consists of one std::vector<int> listRanges_ of size number of lists plus one and a std::vector<T> elements_ with the elements of all lists concatenated. List i is stored in entries listRanges_[i] to listRanges_[i+1] in elements_.
- Note
- This class is currently limited to arithmetic types, mainly because this should only be used for performance critical applications. When performance is not critical, a std::vector of std::vector can be used.
- Template Parameters
-
|
| ListOfLists ()=default |
| Constructs an empty list of lists.
|
|
| ListOfLists (std::vector< int > &&listRanges, std::vector< T > &&elements) |
| Constructs a list of list from raw data in internal layout. More...
|
|
std::size_t | size () const |
| Returns the number of lists.
|
|
Index | ssize () const |
| Returns the number of lists. More...
|
|
bool | empty () const |
| Returns whether the list holds no lists.
|
|
int | numElements () const |
| Returns the sum of the number of elements over all lists.
|
|
void | pushBack (ArrayRef< const T > values) |
| Appends a new list with elements values , pass {} to add an empty list.
|
|
void | pushBackListOfSize (int numElements) |
| Appends a new list with numElements elements.
|
|
ArrayRef< const T > | operator[] (std::size_t listIndex) const |
| Returns an ArrayRef to the elements of the list with the given index.
|
|
ArrayRef< const T > | at (std::size_t listIndex) const |
| Returns the list of elements for the list with index listIndex , throws an out_of_range exception when out of range.
|
|
ArrayRef< T > | front () |
| Returns a reference to the first list. More...
|
|
ArrayRef< T > | back () |
| Returns a reference to the final list. More...
|
|
void | clear () |
| Clears the list.
|
|
void | appendListOfLists (const ListOfLists &listOfLists, const T offset=0) |
| Appends a ListOfLists at the end and increments the appended elements by offset .
|
|
ArrayRef< const int > | listRangesView () const |
| Returns concatenated ranges of the lists (see above for details)
|
|
ArrayRef< const T > | elementsView () const |
| Returns the a view of the elements of all lists concatenated.
|
|