TuringSim
C++ framework to simulate abstract computing models
Public Member Functions | List of all members
TuringSim::Memory::Tape::TapeModifier< T > Class Template Reference

Modifier for the Tape class. More...

#include <memory/tape.h>

Public Member Functions

constexpr TapeModifier (Tape< T > &tape)
 Construct a modifier of the tape in parameter. More...
 
constexpr void allocateRight () const
 Allocate some space on the right half-tape. More...
 
constexpr void allocateLeft () const
 Allocate some space on the left half-tape. More...
 
constexpr void allocate () const
 Allocate some space on the tape. More...
 
constexpr void allocateRight (size_t additionalSize) const
 Allocate some space on the right half-tape. More...
 
constexpr void allocateLeft (size_t additionalSize) const
 Allocate some space on the left half-tape. More...
 
constexpr void allocate (size_t additionalSize) const
 Allocate some space on the tape. More...
 
constexpr void shrink () const
 Deallocate unused tape. More...
 
constexpr void setSizeFactor (size_t newSizeFactor) const
 Set the resizing factor. More...
 
constexpr void setPosition (long long int position)
 Change the current position of the I/O head. More...
 
constexpr T & operator[] (long long int position)
 Get a non-const reference to a cell on the tape. More...
 

Detailed Description

template<typename T>
class TuringSim::Memory::Tape::TapeModifier< T >

Modifier for the Tape class.

Template Parameters
Tthe type of the alphabet of the modifiable tape

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.

Definition at line 558 of file tape.h.

Constructor & Destructor Documentation

◆ TapeModifier()

template<typename T >
constexpr TuringSim::Memory::Tape::TapeModifier< T >::TapeModifier ( Tape< T > &  tape)
inlineconstexpr

Construct a modifier of the tape in parameter.

Parameters
[in,out]tapeThe tape to modify. It is captured by reference.

The behaviour of the observer is undefined (and will probably segfault) once the tape destroyed.

Complexity of \(\mathcal{O}(1)\).

Definition at line 569 of file tape.h.

Member Function Documentation

◆ allocate() [1/2]

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::allocate ( ) const
inlineconstexpr

Allocate some space on the tape.

Call allocateRight() and allocateLeft().

Complexity is \(\mathcal{O}(\texttt{sizeFactor}\times (l+r))\) where \(r\) is the size of the right half-tape and \(l\) is the size of the left half-tape.

Definition at line 591 of file tape.h.

◆ allocate() [2/2]

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::allocate ( size_t  additionalSize) const
inlineconstexpr

Allocate some space on the tape.

Parameters
[in]additionalSizeNumber of boxes to allocated on each half-tape.

Call allocateRight(e) and allocateLeft(e).

Complexity is \(\mathcal{O}(l+r+2e)\) where \(r\) is the size of the right half-tape and \(l\) is the size of the left half-tape.

Definition at line 616 of file tape.h.

◆ allocateLeft() [1/2]

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::allocateLeft ( ) const
inlineconstexpr

Allocate some space on the left half-tape.

Multiply the allocated size of the left half-tape by a factor sizeFactor.

Complexity is \(\mathcal{O}(\texttt{sizeFactor}\times l)\) where \(l\) is the size of the left half-tape.

Definition at line 583 of file tape.h.

◆ allocateLeft() [2/2]

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::allocateLeft ( size_t  additionalSize) const
inlineconstexpr

Allocate some space on the left half-tape.

Parameters
[in]additionalSizeNumber of boxes to allocated.

Allocate e boxes on the left half-tape.

Complexity is \(\mathcal{O}(h + \texttt{e})\) where \(h\) is the size of the left half-tape.

Definition at line 607 of file tape.h.

◆ allocateRight() [1/2]

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::allocateRight ( ) const
inlineconstexpr

Allocate some space on the right half-tape.

Multiply the allocated size of the right half-tape by a factor sizeFactor.

Complexity is \(\mathcal{O}(\texttt{sizeFactor}\times r)\) where \(r\) is the size of the right half-tape.

Definition at line 576 of file tape.h.

◆ allocateRight() [2/2]

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::allocateRight ( size_t  additionalSize) const
inlineconstexpr

Allocate some space on the right half-tape.

Parameters
[in]additionalSizeNumber of boxes to allocated.

Allocate e boxes on the right half-tape.

Complexity is \(\mathcal{O}(h + \texttt{e})\) where \(h\) is the size of the right half-tape.

Definition at line 599 of file tape.h.

◆ operator[]()

template<typename T >
constexpr T& TuringSim::Memory::Tape::TapeModifier< T >::operator[] ( long long int  position)
inlineconstexpr

Get a non-const reference to a cell on the tape.

Parameters
positionthe position of the cell to access.
Returns
A modifying reference to the cell.

The returned reference may be invalided when the tape is shrunk.

Definition at line 666 of file tape.h.

◆ setPosition()

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::setPosition ( long long int  position)
inlineconstexpr

Change the current position of the I/O head.

Parameters
positionthe new position.

Definition at line 637 of file tape.h.

◆ setSizeFactor()

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::setSizeFactor ( size_t  newSizeFactor) const
inlineconstexpr

Set the resizing factor.

Parameters
[in]newSizeFactorThe new resizing factor

Change the resizing factor using to resize the half-tapes when needed.

Complexity is \(\mathcal{O}(1)\).

Definition at line 632 of file tape.h.

◆ shrink()

template<typename T >
constexpr void TuringSim::Memory::Tape::TapeModifier< T >::shrink ( ) const
inlineconstexpr

Deallocate unused tape.

Keeps only non blank boxes, the box under the I/O tape and the boxes between. In other words, it deallocate blank boxes to the ends of the tape, except the possibly existing box under the I/O head.

Complexity is \(\mathcal{O}(n)\) where \(n\) is the size of the tape.

Definition at line 624 of file tape.h.


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