|
ADS
Algorithms and Data Structures
|
A SEQUENCE [see ADT.h] realized with cursors, beyond the book: the cells of the lists are the places of a vector, a CursorSpace, and a link is the index of the next cell, 0 being nil (the place 0 is never used). More...
#include "ADS/Contract.h"#include <cstddef>#include <initializer_list>#include <iterator>#include <memory>#include <type_traits>#include <utility>#include <vector>#include "ADS/sequence/impl/CursorList.tpp"Go to the source code of this file.
Classes | |
| class | ADS::CursorSpace< T > |
| the vector of the cells of some CursorList, with its free list More... | |
| struct | ADS::CursorSpace< T >::Cell |
| a cell: the item and the cursor of the next cell, 0 for nil More... | |
| class | ADS::CursorList< T > |
| a SEQUENCE realized with cursors in a CursorSpace More... | |
| class | ADS::CursorList< T >::Iterator< Const > |
| the iterator, on items const if Const More... | |
Namespaces | |
| namespace | ADS |
A SEQUENCE [see ADT.h] realized with cursors, beyond the book: the cells of the lists are the places of a vector, a CursorSpace, and a link is the index of the next cell, 0 being nil (the place 0 is never used).
Several lists can share one space, each being the cursor of its first cell, and the free cells form a further list in the same vector, the free list: insert() takes its first cell, remove() gives the cell back, and a space whose free list is empty doubles its vector, the cursors staying valid. This is how a language with no pointers, or a program that wants its lists in one block of memory, realizes linked lists.
As in SinglyList [see SinglyList.h], the position \( \mathit{pos}_i \) is the cursor of the cell of \( s_{i-1} \) for \( i > 0 \) and 0 for \( i = 0 \), so that insert() and remove() find the link to change at hand and take \( O( 1 ) \) time (amortized, for the growth of the space); \( \mathit{pos}_n \) is the cursor of the last cell (0 if the list is empty) and \( \mathit{pos}_{-1} \) is -1. tail() and prev() scan the list, in \( O( n ) \).
The contracts [see Contract.h]: read(), write() and remove() need a position that holds an item; insert() and write() ensure that \( v \) is read back in its position; the invariant of the space is that the free cells and the cells in use are all the places but 0, the free list having no cycle. A list made with no space has a space of its own; the lists of a space share it, and the space lives as long as one of them does. The operations are defined in CursorList.tpp.