Kùzu C++ API
Loading...
Searching...
No Matches
sel_vector.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include "constants.h"
6#include "types.h"
7#include <span>
8
9namespace kuzu {
10namespace common {
11
13public:
15
16 explicit SelectionVector(sel_t capacity) : selectedSize{0}, capacity{capacity} {
17 selectedPositionsBuffer = std::make_unique<sel_t[]>(capacity);
19 }
20
22
23 bool isUnfiltered() const { return selectedPositions == (sel_t*)&INCREMENTAL_SELECTED_POS; }
24
25 void setToUnfiltered() { selectedPositions = (sel_t*)&INCREMENTAL_SELECTED_POS; }
27 KU_ASSERT(size <= capacity);
28 selectedPositions = (sel_t*)&INCREMENTAL_SELECTED_POS;
29 selectedSize = size;
30 }
31
32 // Set to filtered is not very accurate. It sets selectedPositions to a mutable array.
33 void setToFiltered() { selectedPositions = selectedPositionsBuffer.get(); }
34 void setToFiltered(sel_t size) {
35 KU_ASSERT(size <= capacity && selectedPositionsBuffer);
36 selectedPositions = selectedPositionsBuffer.get();
37 selectedSize = size;
38 }
39
40 std::span<sel_t> getMultableBuffer() {
41 return std::span<sel_t>(selectedPositionsBuffer.get(), capacity);
42 }
43 std::span<sel_t> getSelectedPositions() const {
44 return std::span<sel_t>(selectedPositions, selectedSize);
45 }
46
47 sel_t getSelSize() const { return selectedSize; }
48 void setSelSize(sel_t size) {
49 KU_ASSERT(size <= capacity);
50 selectedSize = size;
51 }
52 void incrementSelSize(sel_t increment = 1) {
53 KU_ASSERT(selectedSize < capacity);
54 selectedSize += increment;
55 }
56
57 sel_t operator[](sel_t index) const {
58 KU_ASSERT(index < capacity);
59 return selectedPositions[index];
60 }
62 KU_ASSERT(index < capacity);
63 return selectedPositions[index];
64 }
65
66private:
67 sel_t selectedSize;
68 sel_t capacity;
69 std::unique_ptr<sel_t[]> selectedPositionsBuffer;
70 sel_t* selectedPositions;
71};
72
73} // namespace common
74} // namespace kuzu
#define KUZU_API
Definition api.h:25
#define KU_ASSERT(condition)
Definition assert.h:19
Definition sel_vector.h:12
void setToUnfiltered()
Definition sel_vector.h:25
std::span< sel_t > getSelectedPositions() const
Definition sel_vector.h:43
void setToFiltered()
Definition sel_vector.h:33
SelectionVector()
Definition sel_vector.h:21
sel_t & operator[](sel_t index)
Definition sel_vector.h:61
static KUZU_API const sel_t INCREMENTAL_SELECTED_POS[DEFAULT_VECTOR_CAPACITY]
Definition sel_vector.h:14
void setToUnfiltered(sel_t size)
Definition sel_vector.h:26
bool isUnfiltered() const
Definition sel_vector.h:23
void setToFiltered(sel_t size)
Definition sel_vector.h:34
sel_t getSelSize() const
Definition sel_vector.h:47
void incrementSelSize(sel_t increment=1)
Definition sel_vector.h:52
SelectionVector(sel_t capacity)
Definition sel_vector.h:16
sel_t operator[](sel_t index) const
Definition sel_vector.h:57
void setSelSize(sel_t size)
Definition sel_vector.h:48
std::span< sel_t > getMultableBuffer()
Definition sel_vector.h:40
constexpr uint64_t DEFAULT_VECTOR_CAPACITY
Definition constants.h:12
uint64_t sel_t
Definition types.h:24
Definition alter_type.h:5