1 | #include "duckdb/common/types/selection_vector.hpp" |
---|---|
2 | #include "duckdb/common/printer.hpp" |
3 | |
4 | namespace duckdb { |
5 | |
6 | string SelectionVector::ToString(idx_t count) const { |
7 | string result = "Selection Vector ("+ std::to_string(count) + ") ["; |
8 | for (idx_t i = 0; i < count; i++) { |
9 | if (i != 0) { |
10 | result += ", "; |
11 | } |
12 | result += std::to_string(get_index(i)); |
13 | } |
14 | result += "]"; |
15 | return result; |
16 | } |
17 | |
18 | void SelectionVector::Print(idx_t count) const { |
19 | Printer::Print(ToString(count)); |
20 | } |
21 | |
22 | buffer_ptr<SelectionData> SelectionVector::Slice(const SelectionVector &sel, idx_t count) { |
23 | auto data = make_buffer<SelectionData>(count); |
24 | auto result_ptr = data->owned_data.get(); |
25 | // for every element, we perform result[i] = target[new[i]] |
26 | for (idx_t i = 0; i < count; i++) { |
27 | auto new_idx = sel.get_index(i); |
28 | auto idx = this->get_index(new_idx); |
29 | result_ptr[i] = idx; |
30 | } |
31 | return data; |
32 | } |
33 | |
34 | } // namespace duckdb |
35 |