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

a list of blocks of \( b - 1 \) to \( b + 1 \) items, with \( O( n / b ) \) pointers More...

#include <ADS/sequence/SEList.h>

Classes

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

Public types

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
using iterator = Iterator< false >
 the iterator on the items
using const_iterator = Iterator< true >
 on the constant items

Public member functions

 SEList (std::size_t b=63)
 the empty list with blocks of \( b + 1 \) items at most
 SEList (std::initializer_list< T > l)
 the items of l, in order, with blocks of \( 64 \) items at most
 SEList (const SEList &o)
 a copy of o, with its \( b \)
 SEList (SEList &&o) noexcept
 the blocks of o, which is left empty
SEList & operator= (SEList o) noexcept
 the items of o, by copy and swap
 ~SEList ()
 destroys the items and frees the blocks
void swap (SEList &o) noexcept
 exchanges the blocks with those of o
bool empty (void) const
 true if there is no item
std::size_t size (void) const
 the number \( n \) of items
std::size_t block (void) const
 the parameter \( b \)
std::size_t blocks (void) const
 the number of blocks
std::size_t capacity (void) const
 the places of the blocks, \( b + 1 \) each, at most \( n + O( b + n / b ) \)
T & operator[] (std::size_t i)
 the item of rank \( i \), \( O( 1 + \min\{ i , n - i \} / b ) \)
const T & operator[] (std::size_t i) const
 the item of rank \( i \), constant
const T & front (void) const
 the first item
const T & back (void) const
 the last item
void insert (std::size_t i, const T &x)
 puts \( x \) at the rank \( i \), in \( O( b + \min\{ i , n - i \} / b ) \) amortized time
void erase (std::size_t i)
 removes the item of rank \( i \), in \( O( b + \min\{ i , n - i \} / b ) \) amortized time
void push_front (const T &x)
 \( x \) at the front, \( O( 1 ) \)
void push_back (const T &x)
 \( x \) at the back, \( O( 1 ) \)
void pop_front (void)
 removes the first item, \( O( 1 ) \)
void pop_back (void)
 removes the last item, \( O( 1 ) \)
void clear (void)
 removes all the items and frees the blocks
bool operator== (const SEList &o) const
 the same items in the same order
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

Detailed description

template<class T>
class ADS::SEList< T >

a list of blocks of \( b - 1 \) to \( b + 1 \) items, with \( O( n / b ) \) pointers

Member typedef documentation

◆ const_iterator

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

on the constant items

◆ const_reference

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

a constant reference

◆ difference_type

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

the type of the distances

◆ iterator

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

the iterator on the items

◆ reference

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

a reference to an item

◆ size_type

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

the type of the sizes

◆ value_type

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

the type of the items

Constructor and destructor documentation

◆ SEList() [1/4]

template<class T>
ADS::SEList< T >::SEList ( std::size_t b = 63)
explicit

the empty list with blocks of \( b + 1 \) items at most

Precondition
\( b \ge 3 \)

◆ SEList() [2/4]

template<class T>
ADS::SEList< T >::SEList ( std::initializer_list< T > l)

the items of l, in order, with blocks of \( 64 \) items at most

◆ SEList() [3/4]

template<class T>
ADS::SEList< T >::SEList ( const SEList< T > & o)

a copy of o, with its \( b \)

◆ SEList() [4/4]

template<class T>
ADS::SEList< T >::SEList ( SEList< T > && o)
noexcept

the blocks of o, which is left empty

◆ ~SEList()

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

destroys the items and frees the blocks

Member function documentation

◆ back()

template<class T>
const T & ADS::SEList< T >::back ( void ) const
nodiscard

the last item

Precondition
the list is not empty

◆ begin() [1/2]

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

the iterator on the first item

◆ begin() [2/2]

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

the constant iterator on the first item

◆ block()

template<class T>
std::size_t ADS::SEList< T >::block ( void ) const
inlinenodiscard

the parameter \( b \)

◆ blocks()

template<class T>
std::size_t ADS::SEList< T >::blocks ( void ) const
inlinenodiscard

the number of blocks

◆ capacity()

template<class T>
std::size_t ADS::SEList< T >::capacity ( void ) const
inlinenodiscard

the places of the blocks, \( b + 1 \) each, at most \( n + O( b + n / b ) \)

◆ clear()

template<class T>
void ADS::SEList< T >::clear ( void )

removes all the items and frees the blocks

◆ empty()

template<class T>
bool ADS::SEList< T >::empty ( void ) const
inlinenodiscard

true if there is no item

◆ end() [1/2]

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

the iterator past the last item

◆ end() [2/2]

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

the constant iterator past the last item

◆ erase()

template<class T>
void ADS::SEList< T >::erase ( std::size_t i)

removes the item of rank \( i \), in \( O( b + \min\{ i , n - i \} / b ) \) amortized time

In pseudocode (Morin, section 3.3), a middle block left with \( b - 2 \) items borrowing from the next ones:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{erase}( i ) \cr 2 & \quad ( u , j ) \gets \mathrm{locate}( i );\ u.\mathrm{erase}( j ); \ n \gets n - 1 \cr 3 & \quad \textbf{if}\ |u| = 0\ \textbf{then}\ \text{drop } u; \ \textbf{return} \cr 4 & \quad \textbf{if}\ u \text{ is the first or the last block} \ \textbf{or}\ |u| \ge b - 1\ \textbf{then return} \cr 5 & \quad v \gets u.\mathit{next};\ r \gets 0 \cr 6 & \quad \textbf{while}\ r < b\ \textbf{and}\ v \text{ is a middle } \text{block}\ \textbf{and}\ |v| = b - 1\ \textbf{do}\ v \gets v.\mathit{next};\ r \gets r + 1 \cr 7 & \quad \textbf{if}\ r = b\ \textbf{then}\ \mathrm{gather}( u ); \ \textbf{return} \cr 8 & \quad \textbf{while}\ u \ne v\ \textbf{do}\ u.\mathrm{pushBack}( u.\mathit{next}.\mathrm{popFront}() );\ u \gets u.\mathit{next} \cr 9 & \quad \textbf{if}\ |v| = 0\ \textbf{then}\ \text{drop } v \end{array}} \]

Precondition
\( i < n \)
Postcondition
one item less

◆ front()

template<class T>
const T & ADS::SEList< T >::front ( void ) const
nodiscard

the first item

Precondition
the list is not empty

◆ insert()

template<class T>
void ADS::SEList< T >::insert ( std::size_t i,
const T & x )

puts \( x \) at the rank \( i \), in \( O( b + \min\{ i , n - i \} / b ) \) amortized time

In pseudocode (Morin, section 3.3), \( u \) the block of \( i \) and \( j \) the place of \( i \) in it:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( i , x ) \cr 2 & \quad ( u , j ) \gets \mathrm{locate}( i );\ v \gets u;\ r \gets 0 \cr 3 & \quad \textbf{while}\ r < b\ \textbf{and}\ v \ne \textbf{nil} \ \textbf{and}\ |v| = b + 1\ \textbf{do}\ v \gets v.\mathit{next}; \ r \gets r + 1 \cr 4 & \quad \textbf{if}\ r = b\ \textbf{then}\ \mathrm{spread}( u ); \ ( u , j ) \gets \mathrm{locate}( i ) \cr 5 & \quad \textbf{else} \cr 6 & \qquad \textbf{if}\ v = \textbf{nil}\ \textbf{then}\ v \gets \text{a new block at the end} \cr 7 & \qquad \textbf{while}\ v \ne u\ \textbf{do}\ v.\mathrm{pushFront}( v.\mathit{prev}.\mathrm{popBack}() );\ v \gets v.\mathit{prev} \cr 8 & \quad u.\mathrm{insert}( j , x );\ n \gets n + 1 \end{array}} \]

Precondition
\( i \le n \)
Postcondition
one item more, \( x \) at the rank \( i \)

◆ operator=()

template<class T>
SEList & ADS::SEList< T >::operator= ( SEList< T > o)
noexcept

the items of o, by copy and swap

◆ operator==()

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

the same items in the same order

◆ operator[]() [1/2]

template<class T>
T & ADS::SEList< T >::operator[] ( std::size_t i)
nodiscard

the item of rank \( i \), \( O( 1 + \min\{ i , n - i \} / b ) \)

Precondition
\( i < n \)

◆ operator[]() [2/2]

template<class T>
const T & ADS::SEList< T >::operator[] ( std::size_t i) const
nodiscard

the item of rank \( i \), constant

Precondition
\( i < n \)

◆ pop_back()

template<class T>
void ADS::SEList< T >::pop_back ( void )

removes the last item, \( O( 1 ) \)

Precondition
the list is not empty

◆ pop_front()

template<class T>
void ADS::SEList< T >::pop_front ( void )

removes the first item, \( O( 1 ) \)

Precondition
the list is not empty

◆ push_back()

template<class T>
void ADS::SEList< T >::push_back ( const T & x)

\( x \) at the back, \( O( 1 ) \)

◆ push_front()

template<class T>
void ADS::SEList< T >::push_front ( const T & x)

\( x \) at the front, \( O( 1 ) \)

◆ size()

template<class T>
std::size_t ADS::SEList< T >::size ( void ) const
inlinenodiscard

the number \( n \) of items

◆ swap()

template<class T>
void ADS::SEList< T >::swap ( SEList< T > & o)
noexcept

exchanges the blocks with those of o


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