Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::DynSlist< T > Class Template Reference

Dynamic list of elements of type T implemented with a singly linked list of nodes. More...

#include <tpl_dynSlist.H>

Inheritance diagram for Aleph::DynSlist< T >:
[legend]
Collaboration diagram for Aleph::DynSlist< T >:
[legend]

Classes

class  Iterator
 Iterator specialized for DynSlist returning payload references. More...
 

Public Member Functions

 DynSlist ()
 Constructor.
 
 DynSlist (const DynSlist &other)
 
DynSlistoperator= (const DynSlist &other)
 
 DynSlist (DynSlist &&other) noexcept
 
DynSlistoperator= (DynSlist &&other) noexcept
 
Toperator[] (const size_t i)
 Access the element at position i.
 
const Toperator[] (const size_t i) const
 Const overload of operator[].
 
size_t size () const noexcept
 Return the number of stored elements.
 
void insert (const int pos, const T &data)
 Insert an element at position pos.
 
void insert (const int pos, T &&data)
 Insert an element by moving the provided value.
 
void remove (const int pos)
 Remove the node at position pos.
 
virtual ~DynSlist ()
 
- Public Member Functions inherited from Aleph::Slist< T >
 Slist ()=default
 Default constructor.
 
void insert_first (Node *node)
 Insert node right after this sentinel (at the beginning).
 
Noderemove_first_ne () noexcept
 Remove and return the first node without checking emptiness.
 
Noderemove_first ()
 Remove the first node of the list.
 
Nodeget_first ()
 Return a pointer to the first node; throw if the list is empty.
 
const Nodeget_first () const
 Return a pointer to the first node (const overload).
 
Nodeget_first_ne () noexcept
 Return the first node without checking emptiness.
 
const Nodeget_first_ne () const noexcept
 Return the first node without checking emptiness (const overload).
 
- Public Member Functions inherited from Aleph::Snode< T >
Tget_data ()
 Return a modifiable reference to the stored data.
 
const Tget_data () const
 Return a constant reference to the stored data.
 
 Snode ()=default
 Default constructor.
 
 Snode (const T &_data)
 Constructor that copies the value.
 
 Snode (T &&_data)
 Constructor that moves the value.
 
Snoderemove_next ()
 Remove the node right after this and return it.
 
Snode *& get_next ()
 Return the next node after this.
 
const Snodeget_next () const
 Return the next node after this (const overload).
 
Snoderemove_first ()
 Remove and return the first node (for symmetry with list front).
 
const Snodeget_first () const
 Return the first node (const alias of get_next).
 

Private Member Functions

void clear () noexcept
 
Slist< T >::Nodeget_previous_to_pos (const size_t pos, const bool allow_equal)
 

Private Attributes

size_t num_items
 
size_t current_pos
 
Snode< T > * current_node
 

Additional Inherited Members

- Public Types inherited from Aleph::Slist< T >
typedef Snode< TNode
 

Detailed Description

template<typename T>
class Aleph::DynSlist< T >

Dynamic list of elements of type T implemented with a singly linked list of nodes.

Template Parameters
Tdata type stored in each node
See also
Slist Snode Slink

Definition at line 61 of file tpl_dynSlist.H.

Constructor & Destructor Documentation

◆ DynSlist() [1/3]

template<typename T >
Aleph::DynSlist< T >::DynSlist ( )
inline

Constructor.

Definition at line 97 of file tpl_dynSlist.H.

◆ DynSlist() [2/3]

◆ DynSlist() [3/3]

◆ ~DynSlist()

template<typename T >
virtual Aleph::DynSlist< T >::~DynSlist ( )
inlinevirtual

Definition at line 340 of file tpl_dynSlist.H.

References Aleph::DynSlist< T >::clear().

Member Function Documentation

◆ clear()

◆ get_previous_to_pos()

◆ insert() [1/2]

template<typename T >
void Aleph::DynSlist< T >::insert ( const int  pos,
const T data 
)
inline

Insert an element at position pos.

Parameters
[in]posinsertion position in [0, size()]
[in]datavalue to store
Exceptions
std::out_of_rangeif pos is invalid
std::bad_allocon memory exhaustion

Definition at line 304 of file tpl_dynSlist.H.

References Aleph::DynSlist< T >::current_node, Aleph::DynSlist< T >::current_pos, Aleph::Snode< T >::data, Aleph::DynSlist< T >::get_previous_to_pos(), and Aleph::DynSlist< T >::num_items.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ insert() [2/2]

template<typename T >
void Aleph::DynSlist< T >::insert ( const int  pos,
T &&  data 
)
inline

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ operator[]() [1/2]

template<typename T >
T & Aleph::DynSlist< T >::operator[] ( const size_t  i)
inline

Access the element at position i.

Access is O(i) because it requires traversing i nodes.

Parameters
[in]izero-based index to access
Exceptions
std::out_of_rangeif i is outside [0, size()]
Returns
reference to the element at position i

Definition at line 275 of file tpl_dynSlist.H.

References Aleph::Snode< T >::get_data(), Aleph::Snode< T >::get_next(), and Aleph::DynSlist< T >::get_previous_to_pos().

◆ operator[]() [2/2]

template<typename T >
const T & Aleph::DynSlist< T >::operator[] ( const size_t  i) const
inline

Const overload of operator[].

Definition at line 281 of file tpl_dynSlist.H.

References ah_out_of_range_error_if, Aleph::Slist< T >::get_first_ne(), Aleph::maps(), and Aleph::DynSlist< T >::num_items.

◆ remove()

template<typename T >
void Aleph::DynSlist< T >::remove ( const int  pos)
inline

Remove the node at position pos.

Parameters
[in]poszero-based position to erase
Exceptions
std::out_of_rangeif pos is invalid

Definition at line 330 of file tpl_dynSlist.H.

References Aleph::DynSlist< T >::current_node, Aleph::DynSlist< T >::current_pos, Aleph::DynSlist< T >::get_previous_to_pos(), Aleph::maps(), and Aleph::DynSlist< T >::num_items.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ size()

template<typename T >
size_t Aleph::DynSlist< T >::size ( ) const
inlinenoexcept

Return the number of stored elements.

Definition at line 295 of file tpl_dynSlist.H.

References Aleph::DynSlist< T >::num_items.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

Member Data Documentation

◆ current_node

◆ current_pos

◆ num_items


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