sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
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
19
#include "
sparrow/arrow_interface/arrow_array_schema_utils.hpp
"
20
#include "
sparrow/arrow_interface/private_data_ownership.hpp
"
21
#include "
sparrow/buffer/buffer.hpp
"
22
#include "
sparrow/buffer/buffer_view.hpp
"
23
#include "
sparrow/config/config.hpp
"
24
#include "
sparrow/utils/contracts.hpp
"
25
26
namespace
sparrow
27
{
28
35
36
class
arrow_array_private_data
:
public
children_ownership
,
37
public
dictionary_ownership
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
(
46
BufferType
buffers
,
47
const
CHILDREN_OWNERSHIP&
children_ownership
,
48
bool
dictionary_ownership
49
);
50
51
[[nodiscard]]
constexpr
BufferType
&
buffers
() noexcept;
52
[[nodiscard]] constexpr const
BufferType
&
buffers
() const noexcept;
53
54
SPARROW_CONSTEXPR_GCC_11
void
resize_buffers
(
std
::
size_t
size);
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);
58
SPARROW_CONSTEXPR_GCC_11
void
update_buffers_ptrs
();
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
>
71
constexpr
arrow_array_private_data
::
arrow_array_private_data
(
72
BufferType
buffers
,
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>>&
89
arrow_array_private_data::buffers
() const noexcept
90
{
91
return
m_buffers;
92
}
93
94
SPARROW_CONSTEXPR_GCC_11
void
arrow_array_private_data::resize_buffers
(std::size_t size)
95
{
96
m_buffers.resize(size);
97
update_buffers_ptrs
();
98
}
99
100
inline
void
arrow_array_private_data::set_buffer
(std::size_t index,
buffer<std::uint8_t>
&&
buffer
)
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
107
inline
void
arrow_array_private_data::set_buffer
(std::size_t index,
const
buffer_view<std::uint8_t>
&
buffer
)
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
114
SPARROW_CONSTEXPR_GCC_11
void
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
128
SPARROW_CONSTEXPR_GCC_11
void
arrow_array_private_data::update_buffers_ptrs
()
129
{
130
m_buffers_pointers =
to_raw_ptr_vec<std::uint8_t>
(m_buffers);
131
}
132
}
arrow_array_schema_utils.hpp
buffer.hpp
buffer_view.hpp
sparrow::arrow_array_private_data::buffers
constexpr BufferType & buffers() noexcept
Definition
private_data.hpp:83
sparrow::arrow_array_private_data::set_buffer
void set_buffer(std::size_t index, buffer< std::uint8_t > &&buffer)
Definition
private_data.hpp:100
sparrow::arrow_array_private_data::resize_buffer
SPARROW_CONSTEXPR_GCC_11 void resize_buffer(std::size_t index, std::size_t size, std::uint8_t value)
Definition
private_data.hpp:115
sparrow::arrow_array_private_data::arrow_array_private_data
constexpr arrow_array_private_data(BufferType buffers, const CHILDREN_OWNERSHIP &children_ownership, bool dictionary_ownership)
Definition
private_data.hpp:71
sparrow::arrow_array_private_data::resize_buffers
SPARROW_CONSTEXPR_GCC_11 void resize_buffers(std::size_t size)
Definition
private_data.hpp:94
sparrow::arrow_array_private_data::update_buffers_ptrs
SPARROW_CONSTEXPR_GCC_11 void update_buffers_ptrs()
Definition
private_data.hpp:128
sparrow::arrow_array_private_data::BufferType
std::vector< buffer< std::uint8_t > > BufferType
Definition
private_data.hpp:41
sparrow::arrow_array_private_data::buffers_ptrs
constexpr const T ** buffers_ptrs() noexcept
Definition
private_data.hpp:123
sparrow::buffer_view
Definition
buffer_view.hpp:46
sparrow::buffer
Object that owns a piece of contiguous memory.
Definition
buffer.hpp:131
sparrow::buffer::data
constexpr U * data() noexcept
Definition
buffer.hpp:653
sparrow::children_ownership::children_ownership
children_ownership(std::size_t size=0)
sparrow::dictionary_ownership::dictionary_ownership
dictionary_ownership(bool ownership) noexcept
Definition
private_data_ownership.hpp:35
config.hpp
SPARROW_CONSTEXPR_GCC_11
#define SPARROW_CONSTEXPR_GCC_11
Definition
config.hpp:50
contracts.hpp
SPARROW_ASSERT_TRUE
#define SPARROW_ASSERT_TRUE(expr__)
Definition
contracts.hpp:209
sparrow::ranges
Definition
ranges.hpp:88
sparrow
Definition
array.hpp:21
sparrow::to_raw_ptr_vec
constexpr std::vector< T *, Allocator > to_raw_ptr_vec(Range &range)
Create a vector of pointers to elements from a range.
Definition
arrow_array_schema_utils.hpp:185
std
Extensions to the C++ standard library.
Definition
float16_t.hpp:1916
private_data_ownership.hpp
sparrow
arrow_interface
arrow_array
private_data.hpp
Generated by
1.17.0