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

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

Detailed description

template<class T>
class ADS::CursorSpace< T >

the vector of the cells of some CursorList, with its free list

Constructor and destructor documentation

◆ CursorSpace()

template<class T>
ADS::CursorSpace< T >::CursorSpace ( long dim = 8)
explicit

a space of \( \mathit{dim} \) free cells, the places \( 1 , \ldots , \mathit{dim} \)

Precondition
\( \mathit{dim} \ge 1 \)

Member function documentation

◆ capacity()

template<class T>
long ADS::CursorSpace< T >::capacity ( void ) const
nodiscard

the number of places, 0 excluded

◆ give()

template<class T>
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}} \]

Precondition
\( c \) is a cell in use

◆ operator[]() [1/2]

template<class T>
Cell & ADS::CursorSpace< T >::operator[] ( long c)
nodiscard

the cell at the cursor \( c \)

Precondition
\( 1 \le c \le \mathrm{capacity}() \)

◆ operator[]() [2/2]

template<class T>
const Cell & ADS::CursorSpace< T >::operator[] ( long c) const
nodiscard

the cell at the cursor \( c \), constant

Precondition
\( 1 \le c \le \mathrm{capacity}() \)

◆ take()

template<class T>
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}} \]

Postcondition
the result is a cell in use

◆ used()

template<class T>
long ADS::CursorSpace< T >::used ( void ) const
nodiscard

the number of cells in use


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