-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuniteddataset.h
93 lines (79 loc) · 2.11 KB
/
uniteddataset.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// (c) 2016 by University of Delaware, Argonne National Laboratory, San Diego
// Supercomputer Center, National University of Defense Technology,
// National Supercomputer Center in Guangzhou, and Sun Yat-sen University.
//
// See COPYRIGHT in top-level directory.
//
#ifndef MIMIR_UNITED_DATASET_H
#define MIMIR_UNITED_DATASET_H
#include <vector>
#include "interface.h"
namespace MIMIR_NS {
template <typename KeyType, typename ValType>
class UnitedDataset : public Readable<KeyType, ValType>
{
public:
UnitedDataset(std::vector<Readable<KeyType, ValType> *> &datasets)
{
for (auto iter : datasets) {
this->datasets.push_back(iter);
}
dataset_idx = 0;
}
virtual ~UnitedDataset() {}
virtual int open()
{
for (auto iter : datasets) {
iter->open();
}
dataset_idx = 0;
return true;
}
virtual void close()
{
for (auto iter : datasets) {
iter->close();
}
}
virtual int seek(DB_POS pos)
{
int ret = 0;
if (pos == DB_START) {
dataset_idx = 0;
for (auto iter : datasets) {
ret = iter->seek(DB_START);
if (ret != true) return false;
}
}
else if (pos == DB_END) {
dataset_idx = (int) datasets.size() - 1;
ret = datasets[dataset_idx]->seek(DB_END);
if (ret != true) return false;
}
return true;
}
virtual uint64_t get_record_count()
{
uint64_t total_count = 0;
for (auto iter : datasets) {
total_count += iter->get_record_count();
}
return total_count;
}
virtual int read(KeyType *key, ValType *val)
{
int ret = 0;
while (dataset_idx < datasets.size()) {
ret = datasets[dataset_idx]->read(key, val);
if (ret == true) return true;
dataset_idx++;
}
return false;
}
private:
std::vector<Readable<KeyType, ValType> *> datasets;
size_t dataset_idx;
};
} // namespace MIMIR_NS
#endif