sparrow 0.3.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
23
24namespace sparrow
25{
26
33
35 {
36 public:
37
38 using BufferType = std::vector<buffer<std::uint8_t>>;
39
40 explicit constexpr arrow_array_private_data(BufferType buffers, std::size_t children_size = 0);
41
42 [[nodiscard]] constexpr BufferType& buffers() noexcept;
43 [[nodiscard]] constexpr const BufferType& buffers() const noexcept;
44
45 constexpr void resize_buffers(std::size_t size);
46 void set_buffer(std::size_t index, buffer<std::uint8_t>&& buffer);
47 void set_buffer(std::size_t index, const buffer_view<std::uint8_t>& buffer);
48 constexpr void resize_buffer(std::size_t index, std::size_t size, std::uint8_t value);
49 constexpr void update_buffers_ptrs();
50
51 template <class T>
52 [[nodiscard]] constexpr const T** buffers_ptrs() noexcept;
53
54 private:
55
56 BufferType m_buffers;
57 std::vector<std::uint8_t*> m_buffers_pointers;
58 };
59
62 , m_buffers(std::move(buffers))
63 , m_buffers_pointers(to_raw_ptr_vec<std::uint8_t>(m_buffers))
64 {
65 }
66
67 [[nodiscard]] constexpr std::vector<buffer<std::uint8_t>>& arrow_array_private_data::buffers() noexcept
68 {
69 return m_buffers;
70 }
71
72 [[nodiscard]] constexpr const std::vector<buffer<std::uint8_t>>&
74 {
75 return m_buffers;
76 }
77
78 constexpr void arrow_array_private_data::resize_buffers(std::size_t size)
79 {
80 m_buffers.resize(size);
82 }
83
85 {
86 SPARROW_ASSERT_TRUE(index < m_buffers.size());
87 m_buffers[index] = std::move(buffer);
88 m_buffers_pointers[index] = m_buffers[index].data();
89 }
90
92 {
93 SPARROW_ASSERT_TRUE(index < m_buffers.size());
94 m_buffers[index] = buffer;
95 m_buffers_pointers[index] = m_buffers[index].data();
96 }
97
98 constexpr void
99 arrow_array_private_data::resize_buffer(std::size_t index, std::size_t size, std::uint8_t value)
100 {
101 SPARROW_ASSERT_TRUE(index < m_buffers.size());
102 m_buffers[index].resize(size, value);
103 m_buffers_pointers[index] = m_buffers[index].data();
104 }
105
106 template <class T>
107 [[nodiscard]] constexpr const T** arrow_array_private_data::buffers_ptrs() noexcept
108 {
109 return const_cast<const T**>(reinterpret_cast<T**>(m_buffers_pointers.data()));
110 }
111
113 {
114 m_buffers_pointers = to_raw_ptr_vec<std::uint8_t>(m_buffers);
115 }
116}
constexpr BufferType & buffers() noexcept
void set_buffer(std::size_t index, buffer< std::uint8_t > &&buffer)
constexpr void resize_buffer(std::size_t index, std::size_t size, std::uint8_t value)
constexpr arrow_array_private_data(BufferType buffers, std::size_t children_size=0)
constexpr void resize_buffers(std::size_t size)
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:594
constexpr children_ownership(std::size_t size=0)
constexpr std::size_t children_size() const noexcept
#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.