|
ADS
Algorithms and Data Structures
|
the vector of the cells of some CursorList, with its free list More...
#include <ADS/sequence/CursorList.h>
Classes | |
| struct | Cell |
| a cell: the item and the cursor of the next cell, 0 for nil More... | |
Public member functions | |
| CursorSpace (long dim=8) | |
| a space of \( \mathit{dim} \) free cells, the places \( 1 , \ldots , \mathit{dim} \) | |
| Cell & | operator[] (long c) |
| the cell at the cursor \( c \) | |
| const Cell & | operator[] (long c) const |
| the cell at the cursor \( c \), constant | |
| long | take (void) |
| takes the first free cell, doubling the vector if there is none | |
| void | give (long c) |
| gives the cell \( c \) back to the free list | |
| long | capacity (void) const |
| the number of places, 0 excluded | |
| long | used (void) const |
| the number of cells in use | |
the vector of the cells of some CursorList, with its free list
|
explicit |
a space of \( \mathit{dim} \) free cells, the places \( 1 , \ldots , \mathit{dim} \)
|
nodiscard |
the number of places, 0 excluded
| void ADS::CursorSpace< T >::give | ( | long | c | ) |
gives the cell \( c \) back to the free list
In pseudocode (as take()), the cell pushed on the free list:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{give}( k ) \cr 2 & \quad A[ k ].\mathit{next} \gets \mathit{free};\ \mathit{free} \gets k \end{array}} \]
|
nodiscard |
the cell at the cursor \( c \)
|
nodiscard |
the cell at the cursor \( c \), constant
| long ADS::CursorSpace< T >::take | ( | void | ) |
takes the first free cell, doubling the vector if there is none
In pseudocode (the free list of Aho, Hopcroft and Ullman, section 2.2, and of Knuth, section 2.2.3), \( A[ 1 .. c ] \) the cells:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{take}() \cr 2 & \quad \textbf{if}\ \mathit{free} = 0\ \textbf{then}\quad \triangleright\ \text{no free cell: twice the places} \cr 3 & \qquad \text{extend } A \text{ to } A[ 1 .. 2 c ] \cr 4 & \qquad \textbf{for}\ k \gets c + 1\ \textbf{to}\ 2 c - 1 \ \textbf{do}\ A[ k ].\mathit{next} \gets k + 1 \cr 5 & \qquad A[ 2 c ].\mathit{next} \gets 0;\ \mathit{free} \gets c + 1; \ c \gets 2 c \cr 6 & \quad k \gets \mathit{free};\ \mathit{free} \gets A[ k ].\mathit{next};\ A[ k ].\mathit{next} \gets 0 \cr 7 & \quad \textbf{return}\ k \end{array}} \]
|
nodiscard |
the number of cells in use