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

reads a file through a buffer of one block, \( B \) items of the memory More...

#include <ADS/external/TwoLevelMemory.h>

Public member functions

 DiskReader (const DiskFile< T > &f)
 the reader of f, its buffer taken from the memory of f
 DiskReader (const DiskReader &)=delete
 no copy, since the buffer is leased from the memory
DiskReader & operator= (const DiskReader &)=delete
 no copy, since the buffer is leased from the memory
bool hasNext (void) const
 whether some items are not yet scanned
const T & peek (void)
 the next item of the scan, its block read if not in the buffer
T next (void)
 the next item of the scan, and the scan moves past it
std::size_t position (void) const
 the place of the scan
const T & at (std::size_t i)
 the item \( i \), its block read if not in the buffer; the scan goes on from \( i + 1 \)

Detailed description

template<class T>
class ADS::DiskReader< T >

reads a file through a buffer of one block, \( B \) items of the memory

Constructor and destructor documentation

◆ DiskReader() [1/2]

template<class T>
ADS::DiskReader< T >::DiskReader ( const DiskFile< T > & f)
explicit

the reader of f, its buffer taken from the memory of f

Precondition
\( B \) items of memory are free

◆ DiskReader() [2/2]

template<class T>
ADS::DiskReader< T >::DiskReader ( const DiskReader< T > & )
delete

no copy, since the buffer is leased from the memory

Member function documentation

◆ at()

template<class T>
const T & ADS::DiskReader< T >::at ( std::size_t i)

the item \( i \), its block read if not in the buffer; the scan goes on from \( i + 1 \)

In pseudocode (chapter 1, Introduction, of Ferragina's book, beyond the book), \( \beta \) the number of the block in the buffer:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{at}( i ) \cr 2 & \quad \textbf{if}\ \lfloor i / B \rfloor \ne \beta\ \textbf{then} \ \text{read the block } \lfloor i / B \rfloor \text{ into the } \text{buffer};\ \beta \gets \lfloor i / B \rfloor \cr 3 & \quad \mathit{pos} \gets i + 1 \cr 4 & \quad \textbf{return}\ \text{the item } i \bmod B \text{ of the } \text{buffer} \end{array}} \]

Precondition
\( i \) is below the size of the file

◆ hasNext()

template<class T>
bool ADS::DiskReader< T >::hasNext ( void ) const
nodiscard

whether some items are not yet scanned

◆ next()

template<class T>
T ADS::DiskReader< T >::next ( void )

the next item of the scan, and the scan moves past it

Precondition
hasNext()

◆ operator=()

template<class T>
DiskReader & ADS::DiskReader< T >::operator= ( const DiskReader< T > & )
delete

no copy, since the buffer is leased from the memory

◆ peek()

template<class T>
const T & ADS::DiskReader< T >::peek ( void )

the next item of the scan, its block read if not in the buffer

Precondition
hasNext()

◆ position()

template<class T>
std::size_t ADS::DiskReader< T >::position ( void ) const
nodiscard

the place of the scan


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