sparrow 2.2.1
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
array_bitmap_base.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 mplied.
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{
51 template <class D, bool is_mutable>
53 : public std::conditional_t<is_mutable, mutable_array_base<D>, array_crtp_base<D>>
54 {
55 public:
56
57 using base_type = std::conditional_t<is_mutable, mutable_array_base<D>, array_crtp_base<D>>;
58
59 using size_type = std::size_t;
60
61 using bitmap_type = typename base_type::bitmap_type;
62 using const_bitmap_type = typename base_type::const_bitmap_type;
63 using bitmap_iterator = typename base_type::bitmap_iterator;
64 using const_bitmap_iterator = typename base_type::const_bitmap_iterator;
65
66 using bitmap_const_reference = typename base_type::bitmap_const_reference;
67 using difference_type = typename base_type::difference_type;
68
69 using const_bitmap_range = typename base_type::const_bitmap_range;
70
71 using iterator_tag = typename base_type::iterator_tag;
72
73 protected:
74
90
102
115
116 constexpr array_bitmap_base_impl(array_bitmap_base_impl&&) noexcept = default;
117 constexpr array_bitmap_base_impl& operator=(array_bitmap_base_impl&&) noexcept = default;
118
130 [[nodiscard]] constexpr bitmap_type& get_bitmap()
131 requires is_mutable;
132
141 [[nodiscard]] constexpr const const_bitmap_type& get_bitmap() const;
142
157 constexpr void resize_bitmap(size_type new_length, bool value)
158 requires is_mutable;
159
182 requires is_mutable;
183
208 template <std::input_iterator InputIt>
209 requires std::same_as<typename std::iterator_traits<InputIt>::value_type, bool>
210 constexpr bitmap_iterator insert_bitmap(const_bitmap_iterator pos, InputIt first, InputIt last)
211 requires is_mutable;
212
235 requires is_mutable;
236
237 private:
238
239 friend array_crtp_base<D>;
240 friend mutable_array_base<D>;
241 };
242
251 template <class D>
253
263 template <class D>
265
266 /************************************
267 * array_bitmap_base implementation *
268 ************************************/
269
270 template <class D, bool is_mutable>
272 : base_type(std::move(proxy_param))
273 {
274 }
275
276 template <class D, bool is_mutable>
281
282 template <class D, bool is_mutable>
285 {
286 base_type::operator=(rhs);
287 return *this;
288 }
289
290 template <class D, bool is_mutable>
292 requires is_mutable
293 {
294 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
296 return *arrow_proxy.bitmap();
297 }
298
299 template <class D, bool is_mutable>
301 {
302 const arrow_proxy& proxy = this->get_arrow_proxy();
303 SPARROW_ASSERT_TRUE(proxy.const_bitmap().has_value());
304 return *proxy.const_bitmap();
305 }
306
307 template <class D, bool is_mutable>
309 requires is_mutable
310 {
311 this->get_arrow_proxy().resize_bitmap(new_length, value);
312 }
313
314 template <class D, bool is_mutable>
315 constexpr auto
318 requires is_mutable
319 {
320 SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos)
321 SPARROW_ASSERT_TRUE(pos <= this->bitmap_cend())
322 const auto pos_index = static_cast<size_t>(std::distance(this->bitmap_cbegin(), pos));
323 const auto idx = this->get_arrow_proxy().insert_bitmap(pos_index, value, count);
324 return sparrow::next(this->bitmap_begin(), idx);
325 }
326
327 template <class D, bool is_mutable>
328 template <std::input_iterator InputIt>
329 requires std::same_as<typename std::iterator_traits<InputIt>::value_type, bool>
330 constexpr auto
333 requires is_mutable
334 {
335 SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos)
336 SPARROW_ASSERT_TRUE(pos <= this->bitmap_cend());
337 SPARROW_ASSERT_TRUE(first <= last);
338 const auto pos_index = static_cast<size_t>(std::distance(this->bitmap_cbegin(), pos));
339 const auto idx = this->get_arrow_proxy().insert_bitmap(pos_index, std::ranges::subrange(first, last));
340 return sparrow::next(this->bitmap_begin(), idx);
341 }
342
343 template <class D, bool is_mutable>
344 constexpr auto
347 requires is_mutable
348 {
349 SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos)
350 SPARROW_ASSERT_TRUE(pos < this->bitmap_cend())
351 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
352 const auto pos_idx = static_cast<size_t>(std::distance(this->bitmap_cbegin(), pos));
353 const auto idx = arrow_proxy.erase_bitmap(pos_idx, count);
354 return sparrow::next(this->bitmap_begin(), idx);
355 }
356}
array_bitmap_base_impl(arrow_proxy proxy)
Constructs array bitmap base from Arrow proxy.
typename base_type::const_bitmap_range const_bitmap_range
typename base_type::bitmap_iterator bitmap_iterator
constexpr array_bitmap_base_impl(array_bitmap_base_impl &&) noexcept=default
constexpr array_bitmap_base_impl(const array_bitmap_base_impl &)
constexpr void resize_bitmap(size_type new_length, bool value)
constexpr bitmap_iterator insert_bitmap(const_bitmap_iterator pos, bool value, size_type count)
typename base_type::iterator_tag iterator_tag
typename base_type::const_bitmap_iterator const_bitmap_iterator
constexpr array_bitmap_base_impl & operator=(const array_bitmap_base_impl &)
constexpr bitmap_iterator erase_bitmap(const_bitmap_iterator pos, size_type count)
typename base_type::const_bitmap_type const_bitmap_type
std::conditional_t< is_mutable, mutable_array_base< D >, array_crtp_base< D > > base_type
typename base_type::bitmap_const_reference bitmap_const_reference
typename base_type::bitmap_type bitmap_type
typename base_type::difference_type difference_type
SPARROW_API std::optional< bitmap_type > & bitmap()
SPARROW_API const std::optional< const_bitmap_type > & const_bitmap() const
SPARROW_API size_t erase_bitmap(size_t index, size_t count=1)
Erases validity bits starting at specified position.
Base class definining common interface for arrays with a bitmap.
#define SPARROW_ASSERT_TRUE(expr__)
array_bitmap_base_impl< D, true > mutable_array_bitmap_base
Convenient alias for arrays with mutable validity bitmaps.
constexpr InputIt next(InputIt it, Distance n)
Definition iterator.hpp:503
array_bitmap_base_impl< D, false > array_bitmap_base
Convenient alias for arrays with immutable validity bitmaps.
Extensions to the C++ standard library.