ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RecordFile.h File Reference

Files of records on a real disk, for the algorithms whose data do not fit in the internal memory and are read and written by sequential scans only (e.g., the searches with delayed duplicate detection, whose open and closed lists are kept on the disk): where TwoLevelMemory.h simulates the model of Aggarwal and Vitter to count its I/Os, these files are on the file system of the machine, and what they cost is the time of the disk. More...

#include "ADS/Contract.h"
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <string>
#include <type_traits>
#include <vector>
#include "ADS/external/impl/RecordFile.tpp"

Go to the source code of this file.

Classes

class  ADS::RecordFile< T >
 a file of records of a trivially copyable type on the disk More...
class  ADS::RecordWriter< T >
 appends to a RecordFile through a buffer of records, the file opened only to write the buffer More...
class  ADS::TempDirectory
 a directory of its own, removed with what it holds at its destruction More...

Namespaces

namespace  ADS

Detailed description

Files of records on a real disk, for the algorithms whose data do not fit in the internal memory and are read and written by sequential scans only (e.g., the searches with delayed duplicate detection, whose open and closed lists are kept on the disk): where TwoLevelMemory.h simulates the model of Aggarwal and Vitter to count its I/Os, these files are on the file system of the machine, and what they cost is the time of the disk.

  • RecordFile is a file of records of a trivially copyable type T, written as their bytes (hence readable only on a machine with the same layout of T): append() adds records at its end, forEach() scans them in order through a buffer, readAll() loads them, clear() empties the file and remove() deletes it;
  • RecordWriter appends to a RecordFile through a buffer of records, which it writes when it is full and at flush() or at its destruction; the file is opened only to write a buffer, and closed after it, so that a program may keep a writer for each of many files (one per bucket of a search, say) without holding as many descriptors of the system;
  • TempDirectory is a directory of its own, made in the temporary directory of the system (or in a given one) and removed with all that it holds when the object is destroyed, where the files of a run go.

A scan of \( n \) records through a buffer of \( b \) records makes \( \lceil n / b \rceil \) reads of the system, and the writer as many writes; with buffers of some MB each read and each write moves a large contiguous piece of the file, which is what a disk (or an SSD) does at its best throughput [see Theory of external memory]. An error of the file system (a file that cannot be opened, a disk that is full) throws std::runtime_error with the name of the file.

The contracts [see Contract.h]: a buffer of at least one record; a pointer to the records to append unless there are none; the size of a file grows by the records appended. The functions are defined in RecordFile.tpp.

Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa