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

a doubly linked list with one word of links per cell, the exclusive or of the two neighbors More...

#include <ADS/sequence/XorList.h>

Classes

class  Iterator
 the bidirectional iterator, the cell and the one before it, 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

 XorList (void)=default
 the empty list
 XorList (std::initializer_list< T > l)
 the items of l, in order
 XorList (const XorList &o)
 a copy of o, cell by cell
 XorList (XorList &&o) noexcept
 the cells of o, which is left empty
XorList & operator= (XorList o) noexcept
 the items of o, by copy and swap
 ~XorList ()
 destroys the items
void swap (XorList &o) noexcept
 exchanges the cells 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
const T & front (void) const
 the first item
const T & back (void) const
 the last item
void push_front (const T &x)
 \( x \) at the front, \( O( 1 ) \)
void push_back (const T &x)
 \( x \) at the back, \( O( 1 ) \), the mirror of push_front()
void pop_front (void)
 removes the first item, \( O( 1 ) \)
void pop_back (void)
 removes the last item, \( O( 1 ) \), the mirror of pop_front()
void reverse (void)
 the order of the items reversed in \( O( 1 ) \), by exchanging the first and the last cell
void clear (void)
 removes all the items
bool operator== (const XorList &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::XorList< T >

a doubly linked list with one word of links per cell, the exclusive or of the two neighbors

Member typedef documentation

◆ const_iterator

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

on the constant items

◆ const_reference

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

a constant reference

◆ difference_type

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

the type of the distances

◆ iterator

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

the iterator on the items

◆ reference

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

a reference to an item

◆ size_type

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

the type of the sizes

◆ value_type

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

the type of the items

Constructor and destructor documentation

◆ XorList() [1/4]

template<class T>
ADS::XorList< T >::XorList ( void )
default

the empty list

◆ XorList() [2/4]

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

the items of l, in order

◆ XorList() [3/4]

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

a copy of o, cell by cell

◆ XorList() [4/4]

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

the cells of o, which is left empty

◆ ~XorList()

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

destroys the items

Member function documentation

◆ back()

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

the last item

Precondition
the list is not empty

◆ begin() [1/2]

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

the iterator on the first item

◆ begin() [2/2]

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

the constant iterator on the first item

◆ clear()

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

removes all the items

◆ empty()

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

true if there is no item

◆ end() [1/2]

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

the iterator past the last item

◆ end() [2/2]

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

the constant iterator past the last item

◆ front()

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

the first item

Precondition
the list is not empty

◆ operator=()

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

the items of o, by copy and swap

◆ operator==()

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

the same items in the same order

◆ pop_back()

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

removes the last item, \( O( 1 ) \), the mirror of pop_front()

Precondition
the list is not empty
Postcondition
one item less

◆ pop_front()

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

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

In pseudocode (Sinha, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{popFront}() \cr 2 & \quad c \gets h;\ h \gets c.\mathit{link}\quad \triangleright \ \text{its only neighbor} \cr 3 & \quad \textbf{if}\ h \ne \textbf{nil}\ \textbf{then} \ h.\mathit{link} \gets h.\mathit{link} \oplus c\ \textbf{else}\ t \gets \textbf{nil} \cr 4 & \quad \text{free } c \end{array}} \]

Precondition
the list is not empty
Postcondition
one item less

◆ push_back()

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

\( x \) at the back, \( O( 1 ) \), the mirror of push_front()

Postcondition
one item more, \( x \) last

◆ push_front()

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

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

In pseudocode (Sinha, beyond the book), \( h \) the first cell:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{pushFront}( x ) \cr 2 & \quad c \gets \text{a new cell of } x;\ c.\mathit{link} \gets h \cr 3 & \quad \textbf{if}\ h \ne \textbf{nil}\ \textbf{then} \ h.\mathit{link} \gets h.\mathit{link} \oplus c\ \textbf{else}\ t \gets c \cr 4 & \quad h \gets c \end{array}} \]

Postcondition
one item more, \( x \) first

◆ reverse()

template<class T>
void ADS::XorList< T >::reverse ( void )
inline

the order of the items reversed in \( O( 1 ) \), by exchanging the first and the last cell

◆ size()

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

the number \( n \) of items

◆ swap()

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

exchanges the cells with those of o


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