1#include "duckdb/execution/index/art/prefix_segment.hpp"
2
3#include "duckdb/execution/index/art/art.hpp"
4#include "duckdb/execution/index/art/node.hpp"
5
6namespace duckdb {
7
8PrefixSegment &PrefixSegment::New(ART &art, Node &node) {
9
10 node.SetPtr(Node::GetAllocator(art, type: NType::PREFIX_SEGMENT).New());
11 node.type = (uint8_t)NType::PREFIX_SEGMENT;
12
13 auto &segment = PrefixSegment::Get(art, ptr: node);
14 segment.next.Reset();
15 return segment;
16}
17
18PrefixSegment &PrefixSegment::Append(ART &art, uint32_t &count, const uint8_t byte) {
19
20 reference<PrefixSegment> segment(*this);
21 auto position = count % Node::PREFIX_SEGMENT_SIZE;
22
23 // we need a new segment
24 if (position == 0 && count != 0) {
25 segment = PrefixSegment::New(art, node&: next);
26 }
27
28 segment.get().bytes[position] = byte;
29 count++;
30 return segment.get();
31}
32
33PrefixSegment &PrefixSegment::GetTail(const ART &art) {
34
35 reference<PrefixSegment> segment(*this);
36 while (segment.get().next.IsSet()) {
37 segment = PrefixSegment::Get(art, ptr: segment.get().next);
38 }
39 return segment.get();
40}
41
42} // namespace duckdb
43