sparrow 0.9.0
Loading...
Searching...
No Matches
run_end_encoded_iterator.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
21
22namespace sparrow
23{
24
26
27 // this iteratas over the **actual** values of the run encoded array
28 // Ie nullabes values, not values !!!
29 template <bool is_const>
31 run_encoded_array_iterator<is_const>,
32 array_traits::const_reference,
33 std::forward_iterator_tag,
34 array_traits::const_reference>
35 {
36 private:
37
38 using array_ptr_type = std::conditional_t<is_const, const run_end_encoded_array*, run_end_encoded_array*>;
39
40 public:
41
43 run_encoded_array_iterator(array_ptr_type array_ptr, std::uint64_t index, std::uint64_t run_end_index);
44
45 private:
46
47 [[nodiscard]] bool equal(const run_encoded_array_iterator& rhs) const;
48 void increment();
49 [[nodiscard]] array_traits::const_reference dereference() const;
50 array_ptr_type p_array = nullptr;
51 array_wrapper* p_encoded_values_array = nullptr;
52 std::uint64_t m_index = 0; // the current index / the index the user sees
53 std::uint64_t m_run_end_index = 0; // the current index in the run ends array
54 std::uint64_t m_runs_left = 0; // the number of runs left in the current run
55
56 friend class iterator_access;
57 };
58
59 template <bool is_const>
61 array_ptr_type array_ptr,
62 std::uint64_t index,
63 std::uint64_t run_end_index
64 )
65 : p_array(array_ptr)
66 , p_encoded_values_array(array_ptr->p_encoded_values_array.get())
67 , m_index(index)
68 , m_run_end_index(run_end_index)
69 , m_runs_left(array_ptr->get_run_length(index))
70 {
71 }
72
73 template <bool is_const>
74 bool run_encoded_array_iterator<is_const>::equal(const run_encoded_array_iterator& rhs) const
75 {
76 return m_index == rhs.m_index;
77 }
78
79 template <bool is_const>
80 void run_encoded_array_iterator<is_const>::increment()
81 {
82 ++m_index;
83 --m_runs_left;
84 if (m_runs_left == 0 && m_index < p_array->size())
85 {
86 ++m_run_end_index;
87 m_runs_left = p_array->get_run_length(m_run_end_index);
88 }
89 }
90
91 template <bool is_const>
92 typename array_traits::const_reference run_encoded_array_iterator<is_const>::dereference() const
93 {
94 return array_element(*p_encoded_values_array, static_cast<std::size_t>(m_run_end_index));
95 }
96
97} // namespace sparrow
Base class for array type erasure.
run_encoded_array_iterator(array_ptr_type array_ptr, std::uint64_t index, std::uint64_t run_end_index)
SPARROW_API array_traits::const_reference array_element(const array_wrapper &ar, std::size_t index)
mpl::rename< mpl::transform< detail::array_const_reference_t, all_base_types_t >, nullable_variant > const_reference