|
TuringSim
C++ framework to simulate abstract computing models
|
Class to represent a tape memory. More...
#include <memory/tape.h>


Public Types | |
| enum | Movement { Movement::LEFT, Movement::RIGHT, Movement::NONE, Movement::HALT } |
| Enum to encode possible movements. More... | |
Public Types inherited from TuringSim::Memory::MemoryStructure< T, Tape< T >, TapeObserver< T >, TapeModifier< T > > | |
| typedef TapeObserver< T > | Observer |
| The type of observers. | |
| typedef TapeModifier< T > | Modifier |
| The type of modifiers. | |
| typedef T | SymbolType |
| The alphabet type. More... | |
Public Member Functions | |
| constexpr | Tape () |
| Create a new tape. More... | |
| constexpr | Tape (const T &blank) |
| Create a new tape. More... | |
| constexpr | Tape (const Tape< T > &other) |
| Copy a tape. More... | |
| constexpr | Tape (Tape< T > &&other) |
| Move a tape. More... | |
| constexpr Tape< T > & | operator= (const Tape< T > &other) |
| Copy a tape. More... | |
| constexpr Tape< T > & | operator= (Tape< T > &&other) |
| Move a tape. More... | |
| ~Tape ()=default | |
| Destruct the tape. More... | |
| constexpr void | left () |
| Move the I/O head to the left. More... | |
| constexpr void | right () |
| Move the I/O head to the right. More... | |
| constexpr void | move (const Movement &movement) |
| Move the I/O head according to the provided Movement. More... | |
| constexpr const T & | read () const |
| Read the value under the I/O head. More... | |
| constexpr void | write (const T &symbol) |
| Write a value under the I/O head. More... | |
| constexpr void | erase () |
| Write the blank value under the I/O head. More... | |
Public Member Functions inherited from TuringSim::Memory::MemoryStructure< T, Tape< T >, TapeObserver< T >, TapeModifier< T > > | |
| ~MemoryStructure () | |
| Release current observers and modifier. | |
| const std::set< Observer * > & | getObservers () const noexcept |
| Gets the set of observers. More... | |
| const std::optional< Modifier * > & | getModifier () const noexcept |
| Gets the optional modifier. More... | |
Static Public Attributes | |
| static constexpr size_t | MinAllocatedTapeSize = 10 |
| The size allocated when constructing a tape. More... | |
Friends | |
| class | TapeObserver< T > |
| Observer for the Tape class. More... | |
| class | TapeModifier< T > |
| Modifier for the Tape class. More... | |
| template<typename CharT = char, typename Trait = std::char_traits<CharT>> | |
| std::basic_ostream< CharT, Trait > & | operator<< (std::basic_ostream< CharT, Trait > &os, const Movement &movement) |
| Debug printer for tape movement. More... | |
Additional Inherited Members | |
Public Attributes inherited from TuringSim::Memory::MemoryStructure< T, Tape< T >, TapeObserver< T >, TapeModifier< T > > | |
| friend | Observer |
| Observer class. | |
| friend | Modifier |
| Modifier class. | |
Class to represent a tape memory.
| T | Type representing the working alphabet |
A tape is a memory structure made of consecutive boxes. Each box stores a letter of an alphabet. Here, the type T represent the alphabet and instances of T are letters. Moreover, a tape has a I/O head on one box. The only available operations are the move of the head of one box to the left or to the right, read the value under the head and write in the box under the head.
A tape is observationally infinite. Since it is impossible to store an infinite data structure, the tape is elongated when the head come close to the edges of the allocated space. The default value can be specified in the constructor. If it is not, new boxes are default initialized.
|
strong |
Enum to encode possible movements.
Standard movement are LEFT and RIGHT. For practical reason, we add NONE and HALT. Both do not modify the tape. They are useful to build machines: HALT halts the machine while NONE does not.
|
constexpr |
Create a new tape.
The blank value is set to T(). The compilation fails if T is not default constructable.
The initial position is 0. MIN_ALLOCATED_TAPE_SIZE is allocated to the left and the right. The size factor is 2 by default.
Complexity of \(\mathcal{O}(1)\).
|
constexpr |
|
constexpr |
|
constexpr |
|
default |
Destruct the tape.
Complexity of \(\mathcal{O}(n)\) where n is the size of the tape. May be optimized for trivially destructible types.
|
constexpr |
|
constexpr |
Move the I/O head to the left.
Allocation can occur if the head come close enough to an edge of the allocated tape. In this case, the length of the current half tape is multiplied by the size factor.
Amortized complexity of \(\mathcal{O}(1)\), \(\mathcal{O}(\texttt{sizeFactor}\times h)\) where \(h\) is the size of the left half-tape in the worst case.
|
constexpr |
Move the I/O head according to the provided Movement.
| [in] | movement | the movement to perform. |
It is equivalent to left() if movement is Movement::LEFT, and right() if movement is Movement::RIGHT. Otherwise, *this is not changed.
|
constexpr |
|
constexpr |
|
constexpr |
Read the value under the I/O head.
Complexity of \(\mathcal{O}(1)\).
The reference is valid as long as the cell exist. It ceases to exist if the I/O head is closer to 0, the cell is not in the minimal size, there is no non-blank cell that protects the given cell, and TapeObserver<T>::shrink().
|
constexpr |
Move the I/O head to the right.
Allocation can occur if the head come close enough to an edge of the allocated tape. In this case, the length of the current half tape is multiplied by the size factor.
Amortized complexity of \(\mathcal{O}(1)\), \(\mathcal{O}(\texttt{sizeFactor}\times h)\) where \(h\) is the size of the right half-tape in the worst case.
|
constexpr |
|
friend |
|
friend |
Modifier for the Tape class.
The modifier allows to modify private attributes by accessing private methods. For instance, it can be useful to optimize when we know the size needed for the tape. These functions are not directly accessible because these features does not belongs to the abstract model of the tape.
The functions provided by this class are safe. However, it is possible to waste a lot of time by using poorly these features.
|
friend |
|
staticconstexpr |