sparrow 0.3.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
26
27namespace sparrow
28{
29
31
32 // this iteratas over the **actual** values of the run encoded array
33 // Ie nullabes values, not values !!!
34 template <bool CONST>
36 run_encoded_array_iterator<CONST>,
37 array_traits::const_reference,
38 std::forward_iterator_tag,
39 array_traits::const_reference>
40 {
41 private:
42
43 using array_ptr_type = std::conditional_t<CONST, const run_end_encoded_array*, run_end_encoded_array*>;
44
45 public:
46
48 run_encoded_array_iterator(array_ptr_type array_ptr, std::uint64_t index, std::uint64_t run_end_index);
49
50 private:
51
52 [[nodiscard]] bool equal(const run_encoded_array_iterator& rhs) const;
53 void increment();
54 [[nodiscard]] array_traits::const_reference dereference() const;
55 array_ptr_type p_array = nullptr;
56 array_wrapper* p_encoded_values_array = nullptr;
57 std::uint64_t m_index = 0; // the current index / the index the user sees
58 std::uint64_t m_run_end_index = 0; // the current index in the run ends array
59 std::uint64_t m_runs_left = 0; // the number of runs left in the current run
60
61 friend class iterator_access;
62 };
63
64 template <bool CONST>
66 array_ptr_type array_ptr,
67 std::uint64_t index,
68 std::uint64_t run_end_index
69 )
70 : p_array(array_ptr)
71 , p_encoded_values_array(array_ptr->p_encoded_values_array.get())
72 , m_index(index)
73 , m_run_end_index(run_end_index)
74 , m_runs_left(array_ptr->get_run_length(index))
75 {
76 }
77
78 template <bool CONST>
79 bool run_encoded_array_iterator<CONST>::equal(const run_encoded_array_iterator& rhs) const
80 {
81 return m_index == rhs.m_index;
82 }
83
84 template <bool CONST>
85 void run_encoded_array_iterator<CONST>::increment()
86 {
87 ++m_index;
88 --m_runs_left;
89 if (m_runs_left == 0 && m_index < p_array->size())
90 {
91 ++m_run_end_index;
92 m_runs_left = p_array->get_run_length(m_run_end_index);
93 }
94 }
95
96 template <bool CONST>
97 typename array_traits::const_reference run_encoded_array_iterator<CONST>::dereference() const
98 {
99 return array_element(*p_encoded_values_array, static_cast<std::size_t>(m_run_end_index));
100 }
101
102} // 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