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

a disk of blocks of type T, read and written one at a time More...

#include <ADS/external/BlockStore.h>

Public member functions

 BlockStore (TwoLevelMemory *mem=nullptr)
 the empty store, whose I/Os are also counted by mem, if given
T readBlock (std::size_t i) const
 a copy of the block \( i \), one read
void writeBlock (std::size_t i, const T &b)
 \( b \) written in the block \( i \), one write
std::size_t placeBlock (const T &b)
 \( b \) written in a free block, one write; its index
void freeBlock (std::size_t i)
 the block \( i \) given back
const T & peek (std::size_t i) const
 the block \( i \), with no I/O, for the checks
std::size_t blocks (void) const
 the number of blocks in use
std::uint64_t reads (void) const
 the reads so far
std::uint64_t writes (void) const
 the writes so far
void resetCounters (void)
 the counters back to 0

Detailed description

template<class T>
class ADS::BlockStore< T >

a disk of blocks of type T, read and written one at a time

Constructor and destructor documentation

◆ BlockStore()

template<class T>
ADS::BlockStore< T >::BlockStore ( TwoLevelMemory * mem = nullptr)
inlineexplicit

the empty store, whose I/Os are also counted by mem, if given

Member function documentation

◆ blocks()

template<class T>
std::size_t ADS::BlockStore< T >::blocks ( void ) const
inlinenodiscard

the number of blocks in use

◆ freeBlock()

template<class T>
void ADS::BlockStore< T >::freeBlock ( std::size_t i)

the block \( i \) given back

Precondition
the block \( i \) is in use

◆ peek()

template<class T>
const T & ADS::BlockStore< T >::peek ( std::size_t i) const
nodiscard

the block \( i \), with no I/O, for the checks

Precondition
the block \( i \) is in use

◆ placeBlock()

template<class T>
std::size_t ADS::BlockStore< T >::placeBlock ( const T & b)

\( b \) written in a free block, one write; its index

In pseudocode (section 14.1 of Morin's book), \( F \) the stack of the free blocks and \( A \) the array of the blocks:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{placeBlock}( b ) \cr 2 & \quad \textbf{if}\ F = \emptyset\ \textbf{then}\ i \gets |A| ;\ \text{append a block to } A \cr 3 & \quad \textbf{else}\ i \gets \mathrm{pop}( F ) \cr 4 & \quad A[ i ] \gets b;\ \text{count one write} \cr 5 & \quad \textbf{return}\ i \end{array}} \]

◆ readBlock()

template<class T>
T ADS::BlockStore< T >::readBlock ( std::size_t i) const
nodiscard

a copy of the block \( i \), one read

Precondition
the block \( i \) is in use

◆ reads()

template<class T>
std::uint64_t ADS::BlockStore< T >::reads ( void ) const
inlinenodiscard

the reads so far

◆ resetCounters()

template<class T>
void ADS::BlockStore< T >::resetCounters ( void )
inline

the counters back to 0

◆ writeBlock()

template<class T>
void ADS::BlockStore< T >::writeBlock ( std::size_t i,
const T & b )

\( b \) written in the block \( i \), one write

Precondition
the block \( i \) is in use

◆ writes()

template<class T>
std::uint64_t ADS::BlockStore< T >::writes ( void ) const
inlinenodiscard

the writes so far


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