ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BlockStore.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File BlockStore.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
43/*--------------------------------------------------------------------------*/
44/*----------------------------- DEFINITIONS --------------------------------*/
45/*--------------------------------------------------------------------------*/
46
47#ifndef __ADS_BlockStore
48 #define __ADS_BlockStore
49/* self-identification: #endif constant */
50
51/*--------------------------------------------------------------------------*/
52/*------------------------------ INCLUDES ----------------------------------*/
53/*--------------------------------------------------------------------------*/
54
55#include "ADS/Contract.h"
57
58#include <cstddef>
59#include <cstdint>
60#include <vector>
61
62/*--------------------------------------------------------------------------*/
63/*--------------------------- NAMESPACE ------------------------------------*/
64/*--------------------------------------------------------------------------*/
65
66namespace ADS
67{
68
69/*--------------------------------------------------------------------------*/
70/*--------------------------- CLASS BlockStore -----------------------------*/
71/*--------------------------------------------------------------------------*/
72
74template< class T >
76{
77
78/*--------------------------------------------------------------------------*/
79 public:
81 explicit BlockStore( TwoLevelMemory * mem = nullptr ) : f_mem( mem ) { }
82
85 [[nodiscard]] T readBlock( std::size_t i ) const;
86
89 void writeBlock( std::size_t i , const T & b );
90
105 std::size_t placeBlock( const T & b );
106
109 void freeBlock( std::size_t i );
110
113 [[nodiscard]] const T & peek( std::size_t i ) const;
114
116 [[nodiscard]] std::size_t blocks( void ) const {
117 return( f_B.size() - f_free.size() );
118 }
119
121 [[nodiscard]] std::uint64_t reads( void ) const { return( f_reads ); }
122
124 [[nodiscard]] std::uint64_t writes( void ) const { return( f_writes ); }
125
127 void resetCounters( void ) { f_reads = f_writes = 0; }
128
129/*--------------------------------------------------------------------------*/
130 private:
131 std::vector< T > f_B;
132 std::vector< bool > f_used;
133 std::vector< std::size_t > f_free;
134 TwoLevelMemory * f_mem;
135 mutable std::uint64_t f_reads = 0;
136 std::uint64_t f_writes = 0;
137
138 }; // end( class BlockStore )
139
140/*--------------------------------------------------------------------------*/
141
142} // end( namespace ADS )
143
144/*--------------------------------------------------------------------------*/
145/*-------------------------- IMPLEMENTATION --------------------------------*/
146/*--------------------------------------------------------------------------*/
147
148#include "ADS/external/impl/BlockStore.tpp"
149
150/*--------------------------------------------------------------------------*/
151
152#endif /* BlockStore.h included */
153
154/*--------------------------------------------------------------------------*/
155/*------------------------- End File BlockStore.h --------------------------*/
156/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The two-level memory model of Aggarwal and Vitter, simulated so that the algorithms of the external m...
BlockStore(TwoLevelMemory *mem=nullptr)
the empty store, whose I/Os are also counted by mem, if given
Definition BlockStore.h:81
T readBlock(std::size_t i) const
a copy of the block , one read
void resetCounters(void)
the counters back to 0
Definition BlockStore.h:127
std::uint64_t reads(void) const
the reads so far
Definition BlockStore.h:121
void writeBlock(std::size_t i, const T &b)
written in the block , one write
const T & peek(std::size_t i) const
the block , with no I/O, for the checks
std::uint64_t writes(void) const
the writes so far
Definition BlockStore.h:124
std::size_t blocks(void) const
the number of blocks in use
Definition BlockStore.h:116
void freeBlock(std::size_t i)
the block given back
std::size_t placeBlock(const T &b)
written in a free block, one write; its index
the parameters and of the model, the counters of the I/Os and the occupation of the internal memory
Definition TwoLevelMemory.h:94
Definition ADT.h:96