sparrow 0.9.0
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 bitmap_iterator = typename base_type::bitmap_iterator;
63 using const_bitmap_iterator = typename base_type::const_bitmap_iterator;
64
65 using bitmap_const_reference = typename base_type::bitmap_const_reference;
66 using difference_type = typename base_type::difference_type;
67
68 using const_bitmap_range = typename base_type::const_bitmap_range;
69
70 using iterator_tag = typename base_type::iterator_tag;
71
72 protected:
73
89
101
114
115 constexpr array_bitmap_base_impl(array_bitmap_base_impl&&) noexcept = default;
116 constexpr array_bitmap_base_impl& operator=(array_bitmap_base_impl&&) noexcept = default;
117
129 [[nodiscard]] constexpr bitmap_type& get_bitmap()
130 requires is_mutable;
131
140 [[nodiscard]] constexpr const bitmap_type& get_bitmap() const;
141
156 constexpr void resize_bitmap(size_type new_length, bool value)
157 requires is_mutable;
158
181 requires is_mutable;
182
207 template <std::input_iterator InputIt>
208 requires std::same_as<typename std::iterator_traits<InputIt>::value_type, bool>
209 constexpr bitmap_iterator insert_bitmap(const_bitmap_iterator pos, InputIt first, InputIt last)
210 requires is_mutable;
211
234 requires is_mutable;
235
249 constexpr void update()
250 requires is_mutable;
251
262
275 [[nodiscard]] constexpr bitmap_type make_bitmap();
276
277 private:
278
279 bitmap_type m_bitmap;
280
281 friend array_crtp_base<D>;
282 friend mutable_array_base<D>;
283 };
284
293 template <class D>
295
305 template <class D>
307
308 /************************************
309 * array_bitmap_base implementation *
310 ************************************/
311
312 template <class D, bool is_mutable>
314 : base_type(std::move(proxy_param))
315 , m_bitmap(make_bitmap())
316 {
317 }
318
319 template <class D, bool is_mutable>
325
326 template <class D, bool is_mutable>
329 {
330 base_type::operator=(rhs);
331 m_bitmap = make_bitmap();
332 return *this;
333 }
334
335 template <class D, bool is_mutable>
337 requires is_mutable
338 {
339 return m_bitmap;
340 }
341
342 template <class D, bool is_mutable>
344 {
345 return m_bitmap;
346 }
347
348 template <class D, bool is_mutable>
350 {
351 constexpr size_t bitmap_buffer_index = 0;
352 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
353 SPARROW_ASSERT_TRUE(arrow_proxy.buffers().size() > bitmap_buffer_index);
354 const auto bitmap_size = arrow_proxy.length() + arrow_proxy.offset();
355 return bitmap_type(arrow_proxy.buffers()[bitmap_buffer_index].data(), bitmap_size);
356 }
357
358 template <class D, bool is_mutable>
360 requires is_mutable
361 {
362 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
363 const size_t new_size = new_length + arrow_proxy.offset();
364 arrow_proxy.resize_bitmap(new_size, value);
365 }
366
367 template <class D, bool is_mutable>
368 constexpr auto
371 requires is_mutable
372 {
373 SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos)
374 SPARROW_ASSERT_TRUE(pos <= this->bitmap_cend())
375 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
376 const auto pos_index = static_cast<size_t>(std::distance(this->bitmap_cbegin(), pos))
378 const auto idx = arrow_proxy.insert_bitmap(pos_index, value, count);
379 return sparrow::next(this->bitmap_begin(), idx);
380 }
381
382 template <class D, bool is_mutable>
383 template <std::input_iterator InputIt>
384 requires std::same_as<typename std::iterator_traits<InputIt>::value_type, bool>
385 constexpr auto
388 requires is_mutable
389 {
390 SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos)
391 SPARROW_ASSERT_TRUE(pos <= this->bitmap_cend());
392 SPARROW_ASSERT_TRUE(first <= last);
393 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
394 const auto pos_index = static_cast<size_t>(std::distance(this->bitmap_cbegin(), pos))
396 const auto idx = arrow_proxy.insert_bitmap(pos_index, std::ranges::subrange(first, last));
397 return sparrow::next(this->bitmap_begin(), idx);
398 }
399
400 template <class D, bool is_mutable>
401 constexpr auto
404 requires is_mutable
405 {
406 SPARROW_ASSERT_TRUE(this->bitmap_cbegin() <= pos)
407 SPARROW_ASSERT_TRUE(pos < this->bitmap_cend())
408 arrow_proxy& arrow_proxy = this->get_arrow_proxy();
409 const auto pos_idx = static_cast<size_t>(std::distance(this->bitmap_cbegin(), pos));
410 const auto idx = arrow_proxy.erase_bitmap(pos_idx, count);
411 return sparrow::next(this->bitmap_begin(), idx);
412 }
413
414 template <class D, bool is_mutable>
416 requires is_mutable
417 {
418 m_bitmap = make_bitmap();
419 }
420}
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 non_owning_dynamic_bitset< uint8_t > get_non_owning_dynamic_bitset()
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)
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 size_t offset() const
Gets the starting offset within the buffers.
SPARROW_API size_t length() const
Gets the number of elements in the array.
SPARROW_API void resize_bitmap(size_t new_size, bool value=true)
Resizes the validity bitmap buffer.
SPARROW_API size_t erase_bitmap(size_t index, size_t count=1)
Erases validity bits starting at specified position.
SPARROW_API const std::vector< sparrow::buffer_view< uint8_t > > & buffers() const
Gets const reference to the buffer views.
SPARROW_API size_t insert_bitmap(size_t index, bool value, size_t count=1)
Inserts validity bits with the same value 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.