ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::CursorList< T > Class Template Reference

a SEQUENCE realized with cursors in a CursorSpace More...

#include <ADS/sequence/CursorList.h>

Classes

class  Iterator
 the iterator, on items const if Const More...

Public types

using Item = T
 the type of the items
using Pos = long
 the cursor of the cell before the item
using value_type = T
 the type of the items
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using reference = T &
 a reference to an item
using const_reference = const T &
 a constant reference to an item
using iterator = Iterator< false >
 the iterator on the items
using const_iterator = Iterator< true >
 the iterator on the constant items

Public member functions

 CursorList (void)
 the empty list, in a space of its own
 CursorList (std::shared_ptr< CursorSpace< T > > S)
 the empty list in the space \( S \), shared with other lists
 CursorList (std::initializer_list< T > items)
 the list of the given items, in a space of its own
 CursorList (const CursorList &other)
 a copy of the items of other, in the same space
 CursorList (CursorList &&other) noexcept
 the cells of other, which is left empty in the same space
CursorList & operator= (CursorList other) noexcept
 the items of other, by copy and swap
 ~CursorList ()
 gives the cells back to the free list of the space
void swap (CursorList &other) noexcept
 exchanges the cells, and the spaces, with other
bool empty (void) const
 true if there is no item
bool finished (Pos p) const
 true on \( \mathit{pos}_{-1} = -1 \) and on \( \mathit{pos}_n \)
Pos head (void) const
 \( \mathit{pos}_0 \), i.e., 0
Pos tail (void) const
 the position of the last item, \( O( n ) \), by a scan as in SinglyList::tail()
Pos next (Pos p) const
 the position that follows \( p \)
Pos prev (Pos p) const
 the position that precedes \( p \), \( O( n ) \), by a scan as in SinglyList::prev()
Pos insert (Pos p, const T &v)
 puts \( v \) in the position \( p \), the new item taking the position \( p \)
Pos remove (Pos p)
 removes the item in the position \( p \), whose successor takes the position \( p \)
const T & read (Pos p) const
 the item in the position \( p \)
void write (Pos p, const T &v)
 writes \( v \) in the position \( p \)
bool operator== (const CursorList &o) const
 the same items in the same order
const CursorSpace< T > & space (void) const
 the space of the list
long first (void) const
 the cursor of the first cell, 0 if the list is empty
iterator begin (void)
 the iterator on the first item
iterator end (void)
 the iterator past the last item
const_iterator begin (void) const
 the constant iterator on the first item
const_iterator end (void) const
 the constant iterator past the last item
const_iterator cbegin (void) const
 the constant iterator on the first item
const_iterator cend (void) const
 the constant iterator past the last item
template<std::input_iterator I, std::sentinel_for< I > S>
 CursorList (I first, S last)
 the list of the items of [ first , last ), in their order
void push_front (const T &v)
 \( v \) at the front, for std::front_inserter

Detailed description

template<class T>
class ADS::CursorList< T >

a SEQUENCE realized with cursors in a CursorSpace

Member typedef documentation

◆ const_iterator

template<class T>
using ADS::CursorList< T >::const_iterator = Iterator< true >

the iterator on the constant items

◆ const_reference

template<class T>
using ADS::CursorList< T >::const_reference = const T &

a constant reference to an item

◆ difference_type

template<class T>
using ADS::CursorList< T >::difference_type = std::ptrdiff_t

the type of the distances

◆ Item

template<class T>
using ADS::CursorList< T >::Item = T

the type of the items

◆ iterator

template<class T>
using ADS::CursorList< T >::iterator = Iterator< false >

the iterator on the items

◆ Pos

template<class T>
using ADS::CursorList< T >::Pos = long

the cursor of the cell before the item

◆ reference

template<class T>
using ADS::CursorList< T >::reference = T &

a reference to an item

◆ size_type

template<class T>
using ADS::CursorList< T >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T>
using ADS::CursorList< T >::value_type = T

the type of the items

Constructor and destructor documentation

◆ CursorList() [1/6]

template<class T>
ADS::CursorList< T >::CursorList ( void )

the empty list, in a space of its own

◆ CursorList() [2/6]

template<class T>
ADS::CursorList< T >::CursorList ( std::shared_ptr< CursorSpace< T > > S)
explicit

the empty list in the space \( S \), shared with other lists

◆ CursorList() [3/6]

template<class T>
ADS::CursorList< T >::CursorList ( std::initializer_list< T > items)

the list of the given items, in a space of its own

◆ CursorList() [4/6]

template<class T>
ADS::CursorList< T >::CursorList ( const CursorList< T > & other)

a copy of the items of other, in the same space

◆ CursorList() [5/6]

template<class T>
ADS::CursorList< T >::CursorList ( CursorList< T > && other)
noexcept

the cells of other, which is left empty in the same space

◆ ~CursorList()

template<class T>
ADS::CursorList< T >::~CursorList ( )

gives the cells back to the free list of the space

◆ CursorList() [6/6]

template<class T>
template<std::input_iterator I, std::sentinel_for< I > S>
ADS::CursorList< T >::CursorList ( I first,
S last )

the list of the items of [ first , last ), in their order

Member function documentation

◆ begin() [1/2]

template<class T>
iterator ADS::CursorList< T >::begin ( void )
inlinenodiscard

the iterator on the first item

◆ begin() [2/2]

template<class T>
const_iterator ADS::CursorList< T >::begin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cbegin()

template<class T>
const_iterator ADS::CursorList< T >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class T>
const_iterator ADS::CursorList< T >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ empty()

template<class T>
bool ADS::CursorList< T >::empty ( void ) const
nodiscard

true if there is no item

◆ end() [1/2]

template<class T>
iterator ADS::CursorList< T >::end ( void )
inlinenodiscard

the iterator past the last item

◆ end() [2/2]

template<class T>
const_iterator ADS::CursorList< T >::end ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ finished()

template<class T>
bool ADS::CursorList< T >::finished ( Pos p) const
nodiscard

true on \( \mathit{pos}_{-1} = -1 \) and on \( \mathit{pos}_n \)

◆ first()

template<class T>
long ADS::CursorList< T >::first ( void ) const
nodiscard

the cursor of the first cell, 0 if the list is empty

◆ head()

template<class T>
Pos ADS::CursorList< T >::head ( void ) const
nodiscard

\( \mathit{pos}_0 \), i.e., 0

◆ insert()

template<class T>
Pos ADS::CursorList< T >::insert ( Pos p,
const T & v )

puts \( v \) in the position \( p \), the new item taking the position \( p \)

In pseudocode (Aho, Hopcroft and Ullman, section 2.2), \( S \) the space and \( \ell \) the link that leads to the item in \( p \), i.e., \( S[ p ].\mathit{next} \), or the first cell if \( p = 0 \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( p , v ) \cr 2 & \quad k \gets S.\mathrm{take}();\ S[ k ].\mathit{value} \gets v \cr 3 & \quad S[ k ].\mathit{next} \gets \ell;\ \ell \gets k \cr 4 & \quad \textbf{return}\ p \end{array}} \]

Precondition
\( p \) is not \( \mathit{pos}_{-1} \)
Postcondition
read( p ) is \( v \)

◆ next()

template<class T>
Pos ADS::CursorList< T >::next ( Pos p) const
nodiscard

the position that follows \( p \)

Precondition
\( p \) is not \( \mathit{pos}_n \)

◆ operator=()

template<class T>
CursorList & ADS::CursorList< T >::operator= ( CursorList< T > other)
noexcept

the items of other, by copy and swap

◆ operator==()

template<class T>
bool ADS::CursorList< T >::operator== ( const CursorList< T > & o) const
nodiscard

the same items in the same order

◆ prev()

template<class T>
Pos ADS::CursorList< T >::prev ( Pos p) const
nodiscard

the position that precedes \( p \), \( O( n ) \), by a scan as in SinglyList::prev()

◆ push_front()

template<class T>
void ADS::CursorList< T >::push_front ( const T & v)

\( v \) at the front, for std::front_inserter

◆ read()

template<class T>
const T & ADS::CursorList< T >::read ( Pos p) const
nodiscard

the item in the position \( p \)

Precondition
\( p \) holds an item

◆ remove()

template<class T>
Pos ADS::CursorList< T >::remove ( Pos p)

removes the item in the position \( p \), whose successor takes the position \( p \)

In pseudocode (Aho, Hopcroft and Ullman, section 2.2), \( \ell \) as in insert():

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( p ) \cr 2 & \quad k \gets \ell;\ \ell \gets S[ k ].\mathit{next}\quad \triangleright\ \text{unlink the first cell} \cr 3 & \quad S.\mathrm{give}( k );\ \textbf{return}\ p \end{array}} \]

Precondition
\( p \) holds an item

◆ space()

template<class T>
const CursorSpace< T > & ADS::CursorList< T >::space ( void ) const
nodiscard

the space of the list

◆ swap()

template<class T>
void ADS::CursorList< T >::swap ( CursorList< T > & other)
noexcept

exchanges the cells, and the spaces, with other

◆ tail()

template<class T>
Pos ADS::CursorList< T >::tail ( void ) const
nodiscard

the position of the last item, \( O( n ) \), by a scan as in SinglyList::tail()

◆ write()

template<class T>
void ADS::CursorList< T >::write ( Pos p,
const T & v )

writes \( v \) in the position \( p \)

Precondition
\( p \) holds an item
Postcondition
read( p ) is \( v \)

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