-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.h
More file actions
93 lines (73 loc) · 2.01 KB
/
base.h
File metadata and controls
93 lines (73 loc) · 2.01 KB
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
//===----------------------------------------------------------------------===//
//
// Compaction
//
// base.h
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include <memory>
#include <vector>
#include <variant>
#include <iostream>
#include <sstream>
#include <cassert>
#include <list>
#include <unordered_map>
namespace compaction {
// Some data structures
using std::vector;
using std::list;
using std::shared_ptr;
using std::unique_ptr;
using std::unordered_map;
using std::string;
using idx_t = size_t;
extern size_t kBlockSize;
// Attribute includes three types: integer, float-point number, and the string.
using Attribute = std::variant<size_t, double, std::string>;
enum class AttributeType : uint8_t {
INTEGER = 0,
DOUBLE = 1,
STRING = 2,
INVALID = 3
};
// The vector uses Row ID.
class Vector {
public:
AttributeType type_;
size_t count_;
vector<uint32_t> selection_vector_;
explicit Vector(AttributeType type)
: type_(type), count_(0), selection_vector_(kBlockSize), data_(std::make_shared<vector<Attribute>>(kBlockSize)) {
for (size_t i = 0; i < kBlockSize; ++i) selection_vector_[i] = i;
}
inline void Append(Vector &other, size_t num, size_t offset = 0);
inline void Slice(Vector &other, vector<uint32_t> &selection_vector, size_t count);
inline void Reference(Vector &other);
Attribute &GetValue(size_t idx) {
return (*data_)[idx];
}
inline void Reset() {
count_ = 0;
}
private:
shared_ptr<vector<Attribute>> data_;
};
// A data chunk has some columns.
class DataChunk {
public:
size_t count_;
vector<Vector> data_;
vector<AttributeType> types_;
explicit DataChunk(const vector<AttributeType> &types);
void Append(DataChunk &chunk, size_t num, size_t offset = 0);
void AppendTuple(vector<Attribute> &tuple);
void Slice(DataChunk &other, vector<uint32_t> &selection_vector, size_t count);
void Reset() {
count_ = 0;
for (Vector &col : data_) col.Reset();
};
};
}