The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::utils::FastList< DataT > Class Template Reference

An alternative to std::list, about 70% faster. More...

#include <FastList.hpp>

Classes

class  NodeIterator
 The internal iterator type of FastList. Use FastList<T>::[const_]iterator instead. More...
 

Public Types

using value_type = DataT
 Handy using.
 
using iterator = NodeIterator< false >
 Iterator type.
 
using const_iterator = NodeIterator< true >
 Iterator type, const.
 

Public Member Functions

 FastList (size_t size)
 Construct FastList of a given size.
 
 ~FastList ()
 Destroy (clear) the list.
 
iterator begin ()
 Obtain a beginning iterator.
 
const_iterator begin () const
 Obtain a beginning const_iterator.
 
iterator end ()
 Obtain an end iterator.
 
const_iterator end () const
 Obtain an end const_iterator.
 
DataT & front ()
 Get the front of the fast list non-const.
 
const DataT & front () const
 Get the front of the fast list, const.
 
bool empty () const
 
size_t size () const
 
size_t max_size () const
 
void clear () noexcept
 
iterator erase (const const_iterator &entry)
 Erase an element with the given iterator.
 
template<class ... ArgsT>
iterator emplace (const const_iterator &pos, ArgsT &&...args)
 
template<class ... ArgsT>
iterator emplace_front (ArgsT &&...args)
 Add an element to the front of the list.
 
template<class ... ArgsT>
iterator emplace_back (ArgsT &&...args)
 emplace and object at the back
 
template<class ... ArgsT>
iterator insert (const const_iterator &pos, ArgsT &&...args)
 
void pop_back ()
 Pop the last element off of the list.
 
void pop_front ()
 Pop the first element off of the list.
 

Friends

std::ostream & operator<< (std::ostream &os, const FastList< DataT > &fl)
 

Detailed Description

template<class DataT>
class sparta::utils::FastList< DataT >

An alternative to std::list, about 70% faster.

Template Parameters
TThe object to maintain

This class is a container type that allows back emplacement and random deletion. 'std::list' provides the same type of functionality, but performs heap allocation of the internal nodes. Under the covers, this class does not perform new/delete of the Nodes, but reuses existing ones, performing an inplace-new of the user's object.

Testing shows this class is 70% faster than using std::list. Caveats:

  • The size of FastList is fixed to allow for optimization
  • The API isn't as complete as typical STL container types

Definition at line 46 of file FastList.hpp.

Member Typedef Documentation

◆ const_iterator

template<class DataT >
using sparta::utils::FastList< DataT >::const_iterator = NodeIterator<true>

Iterator type, const.

Definition at line 210 of file FastList.hpp.

◆ iterator

template<class DataT >
using sparta::utils::FastList< DataT >::iterator = NodeIterator<false>

Iterator type.

Definition at line 209 of file FastList.hpp.

◆ value_type

template<class DataT >
using sparta::utils::FastList< DataT >::value_type = DataT

Handy using.

Definition at line 86 of file FastList.hpp.

Constructor & Destructor Documentation

◆ FastList()

template<class DataT >
sparta::utils::FastList< DataT >::FastList ( size_t  size)
inline

Construct FastList of a given size.

Parameters
sizeFixed size of the list

Definition at line 190 of file FastList.hpp.

Here is the call graph for this function:

◆ ~FastList()

template<class DataT >
sparta::utils::FastList< DataT >::~FastList ( )
inline

Destroy (clear) the list.

Definition at line 207 of file FastList.hpp.

Member Function Documentation

◆ begin() [1/2]

template<class DataT >
iterator sparta::utils::FastList< DataT >::begin ( )
inline

Obtain a beginning iterator.

Definition at line 213 of file FastList.hpp.

◆ begin() [2/2]

template<class DataT >
const_iterator sparta::utils::FastList< DataT >::begin ( ) const
inline

Obtain a beginning const_iterator.

Definition at line 218 of file FastList.hpp.

◆ clear()

template<class DataT >
void sparta::utils::FastList< DataT >::clear ( )
inlinenoexcept

Definition at line 245 of file FastList.hpp.

◆ emplace()

template<class DataT >
template<class ... ArgsT>
iterator sparta::utils::FastList< DataT >::emplace ( const const_iterator pos,
ArgsT &&...  args 
)
inline

Definition at line 295 of file FastList.hpp.

◆ emplace_back()

template<class DataT >
template<class ... ArgsT>
iterator sparta::utils::FastList< DataT >::emplace_back ( ArgsT &&...  args)
inline

emplace and object at the back

Parameters
argsThe arguments to the T constructor
Returns
iterator of the emplaced item

Definition at line 372 of file FastList.hpp.

◆ emplace_front()

template<class DataT >
template<class ... ArgsT>
iterator sparta::utils::FastList< DataT >::emplace_front ( ArgsT &&...  args)
inline

Add an element to the front of the list.

Template Parameters
argsArguments to be passed to the user type for construction
Returns
iterator to the newly emplaced object

Definition at line 339 of file FastList.hpp.

◆ empty()

template<class DataT >
bool sparta::utils::FastList< DataT >::empty ( ) const
inline
Returns
Is this container empty?

Definition at line 235 of file FastList.hpp.

◆ end() [1/2]

template<class DataT >
iterator sparta::utils::FastList< DataT >::end ( )
inline

Obtain an end iterator.

Definition at line 223 of file FastList.hpp.

◆ end() [2/2]

template<class DataT >
const_iterator sparta::utils::FastList< DataT >::end ( ) const
inline

Obtain an end const_iterator.

Definition at line 226 of file FastList.hpp.

◆ erase()

template<class DataT >
iterator sparta::utils::FastList< DataT >::erase ( const const_iterator entry)
inline

Erase an element with the given iterator.

Parameters
entryIterator to the entry being erased

Definition at line 256 of file FastList.hpp.

Here is the call graph for this function:

◆ front() [1/2]

template<class DataT >
DataT & sparta::utils::FastList< DataT >::front ( )
inline

Get the front of the fast list non-const.

Definition at line 229 of file FastList.hpp.

Here is the call graph for this function:

◆ front() [2/2]

template<class DataT >
const DataT & sparta::utils::FastList< DataT >::front ( ) const
inline

Get the front of the fast list, const.

Definition at line 232 of file FastList.hpp.

Here is the call graph for this function:

◆ insert()

template<class DataT >
template<class ... ArgsT>
iterator sparta::utils::FastList< DataT >::insert ( const const_iterator pos,
ArgsT &&...  args 
)
inline

Insert an element at a specific place in the list. Really just an alias for emplace

Definition at line 401 of file FastList.hpp.

◆ max_size()

template<class DataT >
size_t sparta::utils::FastList< DataT >::max_size ( ) const
inline
Returns
The maximum size of this list

Definition at line 241 of file FastList.hpp.

◆ pop_back()

template<class DataT >
void sparta::utils::FastList< DataT >::pop_back ( )
inline

Pop the last element off of the list.

Definition at line 406 of file FastList.hpp.

Here is the call graph for this function:

◆ pop_front()

template<class DataT >
void sparta::utils::FastList< DataT >::pop_front ( )
inline

Pop the first element off of the list.

Definition at line 413 of file FastList.hpp.

Here is the call graph for this function:

◆ size()

template<class DataT >
size_t sparta::utils::FastList< DataT >::size ( ) const
inline
Returns
The current size of the container

Definition at line 238 of file FastList.hpp.

Friends And Related Symbol Documentation

◆ operator<<

template<class DataT >
std::ostream & operator<< ( std::ostream &  os,
const FastList< DataT > &  fl 
)
friend

Definition at line 422 of file FastList.hpp.


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