a list of blocks of \( b - 1 \) to \( b + 1 \) items, with \( O( n / b ) \) pointers
More...
|
| | 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
|
template<class T>
class ADS::SEList< T >
a list of blocks of \( b - 1 \) to \( b + 1 \) items, with \( O( n / b ) \) pointers
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
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 \)