-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiskBuffer.h
51 lines (38 loc) · 1.09 KB
/
DiskBuffer.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 <vector>
#include <fstream>
#include <string>
#include <mutex>
#include "LabeledData.h"
struct BitMap {
int size;
std::vector<int> is_free;
BitMap(int size, bool all_full);
int get_first_free();
void mark_free(int position);
void mark_filled(int position);
// binary integral logarithm
static int log(int64_t t);
};
class DiskBuffer {
public:
DiskBuffer(const std::string& filename, int feature_size, int num_examples_per_block, int capacity);
DiskBuffer(const DiskBuffer&) = default;
DiskBuffer(DiskBuffer&&) = default;
~DiskBuffer();
int write(const std::vector<char>& data);
std::vector<char> read(int position);
int write_block(const std::vector<ExampleInSampleSet>& data);
std::vector<ExampleInSampleSet> read_block(int position);
private:
BitMap bitmap;
int feature_size;
int num_examples_per_block;
int block_size;
int capacity;
int size;
std::fstream file;
std::string filename;
std::mutex mutex;
static int get_block_size(int feature_size, int num_examples_per_block);
};