-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
segment_tree.hpp
49 lines (40 loc) · 1.41 KB
/
segment_tree.hpp
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
//===----------------------------------------------------------------------===//
// DuckDB
//
// storage/table/segment_tree.hpp
//
//
//===----------------------------------------------------------------------===//
#pragma once
#include "duckdb/common/constants.hpp"
#include "duckdb/storage/storage_lock.hpp"
#include "duckdb/storage/table/segment_base.hpp"
#include <mutex>
namespace duckdb {
struct SegmentNode {
index_t row_start;
SegmentBase *node;
};
//! The SegmentTree maintains a list of all segments of a specific column in a table, and allows searching for a segment
//! by row number
class SegmentTree {
public:
//! The initial segment of the tree
unique_ptr<SegmentBase> root_node;
//! The nodes in the tree, can be binary searched
vector<SegmentNode> nodes;
//! Lock to access or modify the nodes
std::mutex node_lock;
public:
//! Gets a pointer to the first segment. Useful for scans.
SegmentBase *GetRootSegment();
//! Gets a pointer to the last segment. Useful for appends.
SegmentBase *GetLastSegment();
//! Gets a pointer to a specific column segment for the given row
SegmentBase *GetSegment(index_t row_number);
//! Append a column segment to the tree
void AppendSegment(unique_ptr<SegmentBase> segment);
//! Get the segment index of the column segment for the given row (does not lock the segment tree!)
index_t GetSegmentIndex(index_t row_number);
};
} // namespace duckdb