Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::ListOfLists< typename > Class Template Reference

#include <gromacs/utility/listoflists.h>

Description

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
Tvalue type

Public Member Functions

 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.
 

Constructor & Destructor Documentation

template<typename >
gmx::ListOfLists< typename >::ListOfLists ( std::vector< int > &&  listRanges,
std::vector< T > &&  elements 
)
inline

Constructs a list of list from raw data in internal layout.

Does basic consistency checks and throws when one of those fail.

Parameters
[in]listRangesRanges of the lists concatenated (see above), is consumed
[in]elementsElements for all lists concatenated, is consumed

Member Function Documentation

template<typename >
ArrayRef<T> gmx::ListOfLists< typename >::back ( )
inline

Returns a reference to the final list.

Returns
a reference to the final list
template<typename >
ArrayRef<T> gmx::ListOfLists< typename >::front ( )
inline

Returns a reference to the first list.

Returns
a reference to the first list
template<typename >
Index gmx::ListOfLists< typename >::ssize ( ) const
inline

Returns the number of lists.

Note
Use ssize for any expression involving arithmetic operations (including loop indices).

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