-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortedRecordRenderer.h
50 lines (45 loc) · 1.52 KB
/
SortedRecordRenderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include "TournamentTree.h"
#include "params.h"
#include "Metrics.h"
#include "ExternalRun.h"
#include <vector>
#include <fstream>
#include <functional>
using std::vector;
using std::ofstream;
class Materializer; // Forward declaration
class SortedRecordRenderer
{
friend class Materializer;
public:
SortedRecordRenderer (RowSize recordSize, u_int8_t pass, u_int16_t runNumber, bool removeDuplicates, byte * lastRow = nullptr, bool materialize = true);
virtual ~SortedRecordRenderer ();
virtual byte * next () = 0;
string run(); // Render all sorted records and store to a file, return the file name
protected:
RowSize const _recordSize;
u_int64_t _produced;
bool const _removeDuplicates;
byte * _lastRow;
byte * renderRow(std::function<byte *()> retrieveNext, TournamentTree * & tree, ExternalRun * longRun = nullptr);
private:
Materializer * materializer;
};
class Materializer // Materialize the sorted records to a file
{
friend class SortedRecordRenderer;
public:
Materializer (u_int8_t pass, u_int16_t runNumber, SortedRecordRenderer * renderer);
~Materializer ();
private:
SortedRecordRenderer * renderer;
Buffer * outputBuffer;
ofstream outputFile;
u_int8_t deviceType;
string outputFileName;
string getOutputFileName(u_int8_t pass, u_int16_t runNumber);
bool flushOutputBuffer(u_int32_t sizeFilled); // max. 500 KB = 2^19
int switchDevice(u_int32_t sizeFilled);
byte * addRowToOutputBuffer(byte * row); // return pointer to the row in output buffer
};