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

a list of items of type T whose order between two elements is tested in \( O( 1 ) \) by labels on two levels More...

#include <ADS/sequence/OrderMaintenanceList.h>

Public types

using Item = T
 the type of the items
using Element = const Node *
 an element of the list, valid until it is removed

Public member functions

 OrderMaintenanceList (void)=default
 the empty list
 OrderMaintenanceList (const OrderMaintenanceList &)=delete
 no copy, since the elements are pointers
OrderMaintenanceList & operator= (const OrderMaintenanceList &)=delete
 no copy, since the elements are pointers
 ~OrderMaintenanceList ()
 frees the elements
std::size_t size (void) const
 the number \( n \) of elements
Element addAfter (Element e, const T &v)
 a new element of \( v \) right after \( e \), at the front if \( e \) is nil, in \( O( 1 ) \) amortized time
void remove (Element e)
 \( e \) out of the list, and its bucket if it empties, in \( O( 1 ) \) time, no label changed
bool testBefore (Element a, Element b) const
 whether \( a \) comes before \( b \), by the labels of their buckets and by their local labels, in \( O( 1 ) \) time
Element first (void) const
 the first element, nil if the list is empty
Element next (Element e) const
 the element after \( e \), nil after the last
std::pair< std::size_t, std::size_t > relabelWork (void) const
 the number of the relabelings of a range of buckets so far, and the labels written by them and by the buckets labeled again

Static public member functions

static const T & value (Element e)
 the item of \( e \)

Static public attributes

static constexpr std::size_t B = 64
 the most elements of a bucket

Detailed description

template<class T>
class ADS::OrderMaintenanceList< T >

a list of items of type T whose order between two elements is tested in \( O( 1 ) \) by labels on two levels

Member typedef documentation

◆ Element

template<class T>
using ADS::OrderMaintenanceList< T >::Element = const Node *

an element of the list, valid until it is removed

◆ Item

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

the type of the items

Constructor and destructor documentation

◆ OrderMaintenanceList() [1/2]

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

the empty list

◆ OrderMaintenanceList() [2/2]

template<class T>
ADS::OrderMaintenanceList< T >::OrderMaintenanceList ( const OrderMaintenanceList< T > & )
delete

no copy, since the elements are pointers

◆ ~OrderMaintenanceList()

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

frees the elements

Member function documentation

◆ addAfter()

template<class T>
Element ADS::OrderMaintenanceList< T >::addAfter ( Element e,
const T & v )

a new element of \( v \) right after \( e \), at the front if \( e \) is nil, in \( O( 1 ) \) amortized time

In pseudocode (Bender et al., beyond the book), \( \ell \) the local labels and \( b \) the bucket of \( e \) (the first bucket if \( e \) is nil, a new one if the list is empty):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{addAfter}( e , v ) \cr 2 & \quad u \gets \text{a node of } v \text{ linked after } e \text{ in the list and in } b \cr 3 & \quad \mathit{lo} \gets \ell( \text{the element before } u \text{ in } b ) \text{, or } 0 \cr 4 & \quad \mathit{hi} \gets \ell( \text{the element after } u \text{ in } b ) \text{, or } 2^{63} \cr 5 & \quad \textbf{if}\ \mathit{hi} - \mathit{lo} \ge 2\ \textbf{then} \ \ell( u ) \gets \mathit{lo} + \lfloor ( \mathit{hi} - \mathit{lo} ) / 2 \rfloor \cr 6 & \quad \textbf{else}\ \text{label the elements of } b \text{ with } \text{equal gaps} \cr 7 & \quad \textbf{if}\ |b| > B\ \textbf{then} \cr 8 & \qquad b' \gets \text{a new bucket of the last } \lceil |b| / 2 \rceil \text{ elements of } b \cr 9 & \qquad \mathrm{addBucketAfter}( b , b' );\ \text{label } b \text{ and } b' \text{ with equal gaps} \cr 10 & \quad \textbf{return}\ u \end{array}} \]

Precondition
\( e \) is nil or an element of this list

◆ first()

template<class T>
Element ADS::OrderMaintenanceList< T >::first ( void ) const
inlinenodiscard

the first element, nil if the list is empty

◆ next()

template<class T>
Element ADS::OrderMaintenanceList< T >::next ( Element e) const
inlinenodiscard

the element after \( e \), nil after the last

Precondition
\( e \) is an element of this list

◆ operator=()

template<class T>
OrderMaintenanceList & ADS::OrderMaintenanceList< T >::operator= ( const OrderMaintenanceList< T > & )
delete

no copy, since the elements are pointers

◆ relabelWork()

template<class T>
std::pair< std::size_t, std::size_t > ADS::OrderMaintenanceList< T >::relabelWork ( void ) const
inlinenodiscard

the number of the relabelings of a range of buckets so far, and the labels written by them and by the buckets labeled again

◆ remove()

template<class T>
void ADS::OrderMaintenanceList< T >::remove ( Element e)

\( e \) out of the list, and its bucket if it empties, in \( O( 1 ) \) time, no label changed

Precondition
\( e \) is an element of this list

◆ size()

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

the number \( n \) of elements

◆ testBefore()

template<class T>
bool ADS::OrderMaintenanceList< T >::testBefore ( Element a,
Element b ) const
inlinenodiscard

whether \( a \) comes before \( b \), by the labels of their buckets and by their local labels, in \( O( 1 ) \) time

Precondition
\( a \) and \( b \) are elements of this list

◆ value()

template<class T>
const T & ADS::OrderMaintenanceList< T >::value ( Element e)
inlinestaticnodiscard

the item of \( e \)

Member data documentation

◆ B

template<class T>
std::size_t ADS::OrderMaintenanceList< T >::B = 64
staticconstexpr

the most elements of a bucket


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