sparrow 2.1.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
dynamic_bitset_view.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
19
20namespace sparrow
21{
64 template <std::integral T, null_count_policy NCP = tracking_null_count<>>
65 class dynamic_bitset_view : public dynamic_bitset_base<buffer_view<T>, NCP>
66 {
67 public:
68
74
107
146
167
168 constexpr ~dynamic_bitset_view() = default;
169
170 constexpr dynamic_bitset_view(const dynamic_bitset_view&) = default;
171 constexpr dynamic_bitset_view(dynamic_bitset_view&&) noexcept = default;
172
173 constexpr dynamic_bitset_view& operator=(const dynamic_bitset_view&) = default;
174 constexpr dynamic_bitset_view& operator=(dynamic_bitset_view&&) noexcept = default;
175
187 [[nodiscard]] constexpr dynamic_bitset_view slice_view(size_type start, size_type length) const;
188
199 [[nodiscard]] constexpr dynamic_bitset_view slice_view(size_type start) const;
200 };
201
202 template <std::integral T, null_count_policy NCP>
204 : base_type(storage_type(p, p != nullptr ? this->compute_block_count(n) : 0), n)
205 {
206 }
207
208 template <std::integral T, null_count_policy NCP>
213
214 template <std::integral T, null_count_policy NCP>
216 block_type* p,
217 size_type n,
220 )
221 : base_type(storage_type(p, p != nullptr ? this->compute_block_count(n + offset) : 0), n, offset, null_count)
222 {
223 }
224
225 template <std::integral T, null_count_policy NCP>
228 {
229 if (start + length > this->size())
230 {
231 throw std::out_of_range("slice_view: start + length exceeds bitset size");
232 }
233
234 const size_type new_offset = this->offset() + start;
235
236 // Calculate the null count for the slice if tracking is enabled
237 if constexpr (NCP::track_null_count)
238 {
239 size_type slice_null_count = 0;
240 for (size_type i = 0; i < length; ++i)
241 {
242 if (!this->test(start + i))
243 {
244 ++slice_null_count;
245 }
246 }
247 return dynamic_bitset_view(const_cast<block_type*>(this->data()), length, new_offset, slice_null_count);
248 }
249 else
250 {
251 return dynamic_bitset_view(const_cast<block_type*>(this->data()), length, new_offset);
252 }
253 }
254
255 template <std::integral T, null_count_policy NCP>
257 {
258 if (start > this->size())
259 {
260 throw std::out_of_range("slice_view: start exceeds bitset size");
261 }
262
263 return slice_view(start, this->size() - start);
264 }
265}
typename storage_type_without_cvrefpointer::value_type block_type
static constexpr size_type compute_block_count(size_type bits_count) noexcept
typename storage_type_without_cvrefpointer::size_type size_type
constexpr dynamic_bitset_view(block_type *p, size_type n, size_type offset, size_type null_count)
Constructs a bitset view from external memory with null count and offset.
constexpr dynamic_bitset_view(block_type *p, size_type n)
Constructs a bitset view from external memory.
constexpr dynamic_bitset_view(block_type *p, size_type n, size_type offset)
Constructs a bitset view from external memory with null count tracking.
dynamic_bitset_base< buffer_view< T >, tracking_null_count<> > base_type
constexpr dynamic_bitset_view(dynamic_bitset_view &&) noexcept=default
constexpr dynamic_bitset_view slice_view(size_type start, size_type length) const
constexpr dynamic_bitset_view(const dynamic_bitset_view &)=default
constexpr ~dynamic_bitset_view()=default
Concept that checks if a type is a valid null count policy.
Extensions to the C++ standard library.