-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathblock.h
More file actions
115 lines (85 loc) · 2.61 KB
/
block.h
File metadata and controls
115 lines (85 loc) · 2.61 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
#include "columns/column.h"
namespace clickhouse {
struct BlockInfo {
uint8_t is_overflows = 0;
int32_t bucket_num = -1;
};
class Block {
public:
/// Allow to iterate over block's columns.
class Iterator {
public:
Iterator(const Block& block);
/// Name of column.
const std::string& Name() const;
/// Type of column.
TypeRef Type() const;
/// Reference to column object.
ColumnRef Column() const;
/// Move to next column, returns false if next call to IsValid() would return false;
bool Next();
/// Is the iterator still valid.
bool IsValid() const;
size_t ColumnIndex() const {
return idx_;
}
Iterator& operator*() { return *this; }
const Iterator& operator*() const { return *this; }
bool operator==(const Iterator & other) const {
return &block_ == &other.block_ && idx_ == other.idx_;
}
bool operator!=(const Iterator & other) const {
return !(*this == other);
}
Iterator& operator++() {
this->Next();
return *this;
}
private:
friend class Block;
struct ConstructAtEndTag {};
Iterator(const Block& block, ConstructAtEndTag at_end);
Iterator() = delete;
const Block& block_;
size_t idx_;
};
public:
Block();
Block(size_t cols, size_t rows);
~Block();
/// Append named column to the block.
void AppendColumn(const std::string& name, const ColumnRef& col);
/// Count of columns in the block.
size_t GetColumnCount() const;
const BlockInfo& Info() const;
/// Set block info
void SetInfo(BlockInfo info);
/// Count of rows in the block.
size_t GetRowCount() const;
size_t RefreshRowCount();
const std::string& GetColumnName(size_t idx) const {
return columns_.at(idx).name;
}
/// Convenience method to wipe out all rows from all columns
void Clear();
/// Convenience method to do Reserve() on all columns
void Reserve(size_t new_cap);
/// Reference to column by index in the block.
ColumnRef At(size_t idx) const;
ColumnRef operator [] (size_t idx) const { return At(idx); }
Iterator begin() const;
Iterator end() const;
Iterator cbegin() const { return begin(); }
Iterator cend() const { return end(); }
private:
struct ColumnItem {
std::string name;
ColumnRef column;
};
BlockInfo info_;
std::vector<ColumnItem> columns_;
/// Count of rows in the block.
size_t rows_;
};
}