|
| | 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
|
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
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