sparrow 0.6.0
Loading...
Searching...
No Matches
private_data.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
17#include <vector>
18
25
26namespace sparrow
27{
28
35
38 {
39 public:
40
41 using BufferType = std::vector<buffer<std::uint8_t>>;
42
43 template <std::ranges::input_range CHILDREN_OWNERSHIP>
44 requires std::is_same_v<std::ranges::range_value_t<CHILDREN_OWNERSHIP>, bool>
45 explicit constexpr arrow_array_private_data(
47 const CHILDREN_OWNERSHIP& children_ownership,
49 );
50
51 [[nodiscard]] constexpr BufferType& buffers() noexcept;
52 [[nodiscard]] constexpr const BufferType& buffers() const noexcept;
53
55 void set_buffer(std::size_t index, buffer<std::uint8_t>&& buffer);
56 void set_buffer(std::size_t index, const buffer_view<std::uint8_t>& buffer);
57 SPARROW_CONSTEXPR_GCC_11 void resize_buffer(std::size_t index, std::size_t size, std::uint8_t value);
59
60 template <class T>
61 [[nodiscard]] constexpr const T** buffers_ptrs() noexcept;
62
63 private:
64
65 BufferType m_buffers;
66 std::vector<std::uint8_t*> m_buffers_pointers;
67 };
68
69 template <std::ranges::input_range CHILDREN_OWNERSHIP>
70 requires std::is_same_v<std::ranges::range_value_t<CHILDREN_OWNERSHIP>, bool>
73 const CHILDREN_OWNERSHIP& children_ownership_range,
74 bool dictionary_ownership_value
75 )
76 : children_ownership(children_ownership_range)
77 , dictionary_ownership(dictionary_ownership_value)
78 , m_buffers(std::move(buffers))
79 , m_buffers_pointers(to_raw_ptr_vec<std::uint8_t>(m_buffers))
80 {
81 }
82
83 [[nodiscard]] constexpr std::vector<buffer<std::uint8_t>>& arrow_array_private_data::buffers() noexcept
84 {
85 return m_buffers;
86 }
87
88 [[nodiscard]] constexpr const std::vector<buffer<std::uint8_t>>&
90 {
91 return m_buffers;
92 }
93
95 {
96 m_buffers.resize(size);
98 }
99
101 {
102 SPARROW_ASSERT_TRUE(index < m_buffers.size());
103 m_buffers[index] = std::move(buffer);
104 m_buffers_pointers[index] = m_buffers[index].data();
105 }
106
108 {
109 SPARROW_ASSERT_TRUE(index < m_buffers.size());
110 m_buffers[index] = buffer;
111 m_buffers_pointers[index] = m_buffers[index].data();
112 }
113
115 arrow_array_private_data::resize_buffer(std::size_t index, std::size_t size, std::uint8_t value)
116 {
117 SPARROW_ASSERT_TRUE(index < m_buffers.size());
118 m_buffers[index].resize(size, value);
119 m_buffers_pointers[index] = m_buffers[index].data();
120 }
121
122 template <class T>
123 [[nodiscard]] constexpr const T** arrow_array_private_data::buffers_ptrs() noexcept
124 {
125 return const_cast<const T**>(reinterpret_cast<T**>(m_buffers_pointers.data()));
126 }
127
132}
constexpr BufferType & buffers() noexcept
void set_buffer(std::size_t index, buffer< std::uint8_t > &&buffer)
SPARROW_CONSTEXPR_GCC_11 void resize_buffer(std::size_t index, std::size_t size, std::uint8_t value)
constexpr arrow_array_private_data(BufferType buffers, const CHILDREN_OWNERSHIP &children_ownership, bool dictionary_ownership)
SPARROW_CONSTEXPR_GCC_11 void resize_buffers(std::size_t size)
SPARROW_CONSTEXPR_GCC_11 void update_buffers_ptrs()
std::vector< buffer< std::uint8_t > > BufferType
constexpr const T ** buffers_ptrs() noexcept
Object that owns a piece of contiguous memory.
Definition buffer.hpp:109
constexpr U * data() noexcept
Definition buffer.hpp:626
children_ownership(std::size_t size=0)
#define SPARROW_CONSTEXPR_GCC_11
Definition config.hpp:50
#define SPARROW_ASSERT_TRUE(expr__)
constexpr std::vector< T *, Allocator > to_raw_ptr_vec(Range &range)
Create a vector of pointers to elements from a range.