1 | #include "duckdb/execution/index/art/leaf_segment.hpp" |
2 | |
3 | #include "duckdb/execution/index/art/art.hpp" |
4 | #include "duckdb/execution/index/art/node.hpp" |
5 | |
6 | namespace duckdb { |
7 | |
8 | LeafSegment &LeafSegment::New(ART &art, Node &node) { |
9 | |
10 | node.SetPtr(Node::GetAllocator(art, type: NType::LEAF_SEGMENT).New()); |
11 | node.type = (uint8_t)NType::LEAF_SEGMENT; |
12 | |
13 | auto &segment = LeafSegment::Get(art, ptr: node); |
14 | segment.next.Reset(); |
15 | return segment; |
16 | } |
17 | |
18 | void LeafSegment::Free(ART &art, Node &node) { |
19 | |
20 | D_ASSERT(node.IsSet()); |
21 | D_ASSERT(!node.IsSwizzled()); |
22 | |
23 | // free next segment |
24 | auto next_segment = LeafSegment::Get(art, ptr: node).next; |
25 | Node::Free(art, node&: next_segment); |
26 | } |
27 | |
28 | LeafSegment &LeafSegment::Append(ART &art, uint32_t &count, const row_t row_id) { |
29 | |
30 | reference<LeafSegment> segment(*this); |
31 | auto position = count % Node::LEAF_SEGMENT_SIZE; |
32 | |
33 | // we need a new segment |
34 | if (position == 0 && count != 0) { |
35 | segment = LeafSegment::New(art, node&: next); |
36 | } |
37 | |
38 | segment.get().row_ids[position] = row_id; |
39 | count++; |
40 | return segment.get(); |
41 | } |
42 | |
43 | LeafSegment &LeafSegment::GetTail(const ART &art) { |
44 | |
45 | reference<LeafSegment> segment(*this); |
46 | while (segment.get().next.IsSet()) { |
47 | segment = LeafSegment::Get(art, ptr: segment.get().next); |
48 | } |
49 | return segment.get(); |
50 | } |
51 | |
52 | } // namespace duckdb |
53 | |