Kanzi 4.1.0
kanzi::indexed_list< T > Class Template Reference

Indexed list container. More...

#include <kanzi/core/cpp/indexed_list.hpp>

Classes

class  const_iterator
 Const iterator over the values. More...
 
class  element_type
 Value type for internal container. More...
 
class  iterator
 Iterator over the values. More...
 
class  IteratorBase
 Base class for iterator and const_iterator. More...
 
class  sorting_type
 Sorting value type. More...
 

Public Member Functions

Tback ()
 Gets the last element.
 
const Tback () const
 Gets the last element.
 
iterator begin ()
 Gets an iterator to the beginning.
 
const_iterator begin () const
 Gets a const iterator to the beginning.
 
const_iterator cbegin () const
 Gets a const iterator to the beginning.
 
const_iterator cend () const
 Gets a const iterator to the end.
 
void clear ()
 Clear the list.
 
bool empty () const
 Indicates whether or not the indexed list is empty.
 
iterator end ()
 Gets an iterator to the end.
 
const_iterator end () const
 Gets a const iterator to the end.
 
iterator erase (const const_iterator &beginIt, const const_iterator &endIt)
 Erases from a location to another location.
 
iterator erase (const const_iterator &it)
 Erases an element at given location.
 
Tfront ()
 Gets the first element.
 
const Tfront () const
 Gets the first element.
 
vector< size_t > getLocationInSortedOrder () const
 Gets the locations in sorted order list.
 
vector< size_t > getSortedOrder () const
 Gets the sorted order list.
 
 indexed_list ()=default
 Default constructor.
 
 indexed_list (const indexed_list &other)
 Copy constructor.
 
 indexed_list (indexed_list &&other)
 Move constructor.
 
iterator insert (const iterator &it, const T &value)
 Inserts an element into an iterator.
 
iterator insert (const iterator &it, T &&value)
 Inserts an element into an iterator.
 
indexed_listoperator= (const indexed_list &other)
 Copy operator.
 
indexed_listoperator= (indexed_list &&other)
 Move operator.
 
element_typeoperator[] (size_t index)
 Access operator.
 
const element_typeoperator[] (size_t index) const
 Access operator (const).
 
void push_back (const T &value)
 Pushes an element to the end of the list.
 
void push_back (T &&value)
 Pushes an element to the end of the list.
 
void resetSortedOrder ()
 Reset the sorting order to input order.
 
size_t size () const
 Gets the number of elements.
 
vector< sorting_type >::iterator sortingBegin ()
 Gets an iterator to the beginning of the sorting order.
 
vector< sorting_type >::iterator sortingEnd ()
 Gets an iterator to the end of the sorting order.
 
 ~indexed_list ()=default
 Destructor.
 

Static Public Attributes

static const size_t InvalidIndex
 Invalid index to be used across the class.
 

Protected Member Functions

void addNewSortedOrderIndex (size_t newIndex)
 Function ran when new index is added to the sorted order.
 
void fixSortedOrderHostReferences ()
 Fix host pointers in sorted order.
 
void maintainListOrderOnElementErased (size_t index)
 Maintain list order when given element is erased.
 
void maintainListOrderOnNewIndex (element_type &element, size_t oldIndex, size_t newIndex)
 Maintain list order when given element gets a new index.
 
void onNewElementInsertedToBack (size_t newIndex)
 Function ran when new element was inserted to the back of the list.
 
void removeElement (size_t index)
 Function ran when a given element is erased, and the last element needs swapping in.
 
void removeLastElement ()
 Function ran when the last element in the element array is removed.
 
void removeSortedOrderIndex (size_t index)
 Maintain sorted order on given index getting erased.
 

Protected Attributes

vector< element_typem_elements
 Container for actual values.
 
size_t m_first
 Index of the first allocated element.
 
size_t m_last
 Index of the last allocated element.
 
vector< sorting_typem_sortedOrder
 Sorted order (indices).
 

Detailed Description

template<typename T>
class kanzi::indexed_list< T >

Indexed list container.

indexed_list provides access to a container where elements can be accessed using an index, but element order is arbitrary.

The container provides:

  • Amortized constant time insertion.
  • Constant time deletion.
  • Constant time iteration.
  • Constant time access of an element at known location.
  • Linear time access of an element at known index.
Since
Kanzi 4.1.0

Constructor & Destructor Documentation

◆ indexed_list() [1/3]

template<typename T >
kanzi::indexed_list< T >::indexed_list ( )
explicitdefault

Default constructor.

◆ ~indexed_list()

template<typename T >
kanzi::indexed_list< T >::~indexed_list ( )
default

Destructor.

◆ indexed_list() [2/3]

template<typename T >
kanzi::indexed_list< T >::indexed_list ( const indexed_list< T > & other)
inline

Copy constructor.

Parameters
otherOther object.

◆ indexed_list() [3/3]

template<typename T >
kanzi::indexed_list< T >::indexed_list ( indexed_list< T > && other)
inline

Move constructor.

Parameters
otherOther object.

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
indexed_list & kanzi::indexed_list< T >::operator= ( const indexed_list< T > & other)
inline

Copy operator.

Parameters
otherOther object.
Returns
This object.

◆ operator=() [2/2]

template<typename T >
indexed_list & kanzi::indexed_list< T >::operator= ( indexed_list< T > && other)
inline

Move operator.

Parameters
otherOther object.
Returns
This object.

◆ begin() [1/2]

template<typename T >
iterator kanzi::indexed_list< T >::begin ( )
inline

Gets an iterator to the beginning.

Returns
Iterator to the beginning.

◆ begin() [2/2]

template<typename T >
const_iterator kanzi::indexed_list< T >::begin ( ) const
inline

Gets a const iterator to the beginning.

Returns
Const iterator to the beginning.

◆ cbegin()

template<typename T >
const_iterator kanzi::indexed_list< T >::cbegin ( ) const
inline

Gets a const iterator to the beginning.

Returns
Const iterator to the beginning.

◆ end() [1/2]

template<typename T >
iterator kanzi::indexed_list< T >::end ( )
inline

Gets an iterator to the end.

Returns
Iterator to the end.

◆ end() [2/2]

template<typename T >
const_iterator kanzi::indexed_list< T >::end ( ) const
inline

Gets a const iterator to the end.

Returns
Const iterator to the end.

◆ cend()

template<typename T >
const_iterator kanzi::indexed_list< T >::cend ( ) const
inline

Gets a const iterator to the end.

Returns
Const iterator to the end.

◆ sortingBegin()

template<typename T >
vector< sorting_type >::iterator kanzi::indexed_list< T >::sortingBegin ( )
inline

Gets an iterator to the beginning of the sorting order.

Returns
iterator to the sorting order beginning.

◆ sortingEnd()

template<typename T >
vector< sorting_type >::iterator kanzi::indexed_list< T >::sortingEnd ( )
inline

Gets an iterator to the end of the sorting order.

Returns
iterator to the sorting order end.

◆ front() [1/2]

template<typename T >
T & kanzi::indexed_list< T >::front ( )
inline

Gets the first element.

Returns
Reference to the first element.

◆ front() [2/2]

template<typename T >
const T & kanzi::indexed_list< T >::front ( ) const
inline

Gets the first element.

Returns
Const reference to the first element.

◆ back() [1/2]

template<typename T >
T & kanzi::indexed_list< T >::back ( )
inline

Gets the last element.

Returns
Reference to the last element.

◆ back() [2/2]

template<typename T >
const T & kanzi::indexed_list< T >::back ( ) const
inline

Gets the last element.

Returns
Const reference to the last element.

◆ clear()

template<typename T >
void kanzi::indexed_list< T >::clear ( )
inline

Clear the list.

◆ insert() [1/2]

template<typename T >
iterator kanzi::indexed_list< T >::insert ( const iterator & it,
const T & value )
inline

Inserts an element into an iterator.

Parameters
itIterator location.
valueValue to insert.
Returns
Iterator pointing to the inserted element.

◆ insert() [2/2]

template<typename T >
iterator kanzi::indexed_list< T >::insert ( const iterator & it,
T && value )
inline

Inserts an element into an iterator.

Parameters
itIterator location.
valueValue to insert.
Returns
Iterator pointing to the inserted element.

◆ erase() [1/2]

template<typename T >
iterator kanzi::indexed_list< T >::erase ( const const_iterator & it)
inline

Erases an element at given location.

Parameters
itIterator location.
Returns
Iterator pointing to element following the erased element.

◆ erase() [2/2]

template<typename T >
iterator kanzi::indexed_list< T >::erase ( const const_iterator & beginIt,
const const_iterator & endIt )
inline

Erases from a location to another location.

Parameters
beginItBeginning iterator to start removal from.
endItIterator to stop removal at (not erased).
Returns
Iterator pointing to element following the erased element.

◆ push_back() [1/2]

template<typename T >
void kanzi::indexed_list< T >::push_back ( const T & value)
inline

Pushes an element to the end of the list.

Parameters
valueValue to push.

◆ push_back() [2/2]

template<typename T >
void kanzi::indexed_list< T >::push_back ( T && value)
inline

Pushes an element to the end of the list.

Parameters
valueValue to push.

◆ empty()

template<typename T >
bool kanzi::indexed_list< T >::empty ( ) const
inline

Indicates whether or not the indexed list is empty.

Returns
If the list is empty true, false otherwise.

◆ size()

template<typename T >
size_t kanzi::indexed_list< T >::size ( ) const
inline

Gets the number of elements.

Returns
Number of elements inserted.

◆ getSortedOrder()

template<typename T >
vector< size_t > kanzi::indexed_list< T >::getSortedOrder ( ) const
inline

Gets the sorted order list.

This function is intended for tests.

Returns
Ad-hoc generated vector of referred indices.

◆ getLocationInSortedOrder()

template<typename T >
vector< size_t > kanzi::indexed_list< T >::getLocationInSortedOrder ( ) const
inline

Gets the locations in sorted order list.

This function is intended for tests.

Returns
Ad-hoc generated vector of indices in the sorting vector.

◆ resetSortedOrder()

template<typename T >
void kanzi::indexed_list< T >::resetSortedOrder ( )
inline

Reset the sorting order to input order.

◆ fixSortedOrderHostReferences()

template<typename T >
void kanzi::indexed_list< T >::fixSortedOrderHostReferences ( )
inlineprotected

Fix host pointers in sorted order.

◆ onNewElementInsertedToBack()

template<typename T >
void kanzi::indexed_list< T >::onNewElementInsertedToBack ( size_t newIndex)
inlineprotected

Function ran when new element was inserted to the back of the list.

Parameters
newIndexNew index added to the sorted order.

◆ addNewSortedOrderIndex()

template<typename T >
void kanzi::indexed_list< T >::addNewSortedOrderIndex ( size_t newIndex)
inlineprotected

Function ran when new index is added to the sorted order.

Parameters
newIndexNew index to add to the sorted order.

◆ maintainListOrderOnElementErased()

template<typename T >
void kanzi::indexed_list< T >::maintainListOrderOnElementErased ( size_t index)
inlineprotected

Maintain list order when given element is erased.

Parameters
indexList element about to get erased.

◆ maintainListOrderOnNewIndex()

template<typename T >
void kanzi::indexed_list< T >::maintainListOrderOnNewIndex ( element_type & element,
size_t oldIndex,
size_t newIndex )
inlineprotected

Maintain list order when given element gets a new index.

Parameters
elementElement to modify.
oldIndexOld index the element previously was in.
newIndexNew index the element was swapped in to.

◆ removeSortedOrderIndex()

template<typename T >
void kanzi::indexed_list< T >::removeSortedOrderIndex ( size_t index)
inlineprotected

Maintain sorted order on given index getting erased.

Parameters
indexIndex getting removed.

◆ removeLastElement()

template<typename T >
void kanzi::indexed_list< T >::removeLastElement ( )
inlineprotected

Function ran when the last element in the element array is removed.

◆ removeElement()

template<typename T >
void kanzi::indexed_list< T >::removeElement ( size_t index)
inlineprotected

Function ran when a given element is erased, and the last element needs swapping in.

Parameters
indexIndex to remove.

◆ operator[]() [1/2]

template<typename T >
element_type & kanzi::indexed_list< T >::operator[] ( size_t index)
inline

Access operator.

Parameters
indexIndex to access.
Returns
Reference to element.

◆ operator[]() [2/2]

template<typename T >
const element_type & kanzi::indexed_list< T >::operator[] ( size_t index) const
inline

Access operator (const).

Parameters
indexIndex to access.
Returns
Reference to element.

Member Data Documentation

◆ InvalidIndex

template<typename T >
const size_t kanzi::indexed_list< T >::InvalidIndex
static

Invalid index to be used across the class.

◆ m_elements

template<typename T >
vector<element_type> kanzi::indexed_list< T >::m_elements
protected

Container for actual values.

◆ m_first

template<typename T >
size_t kanzi::indexed_list< T >::m_first
protected

Index of the first allocated element.

◆ m_last

template<typename T >
size_t kanzi::indexed_list< T >::m_last
protected

Index of the last allocated element.

◆ m_sortedOrder

template<typename T >
vector<sorting_type> kanzi::indexed_list< T >::m_sortedOrder
protected

Sorted order (indices).


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