sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
layout_utils.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 "
sparrow/types/data_type.hpp
"
18
#include "
sparrow/u8_buffer.hpp
"
19
#include "
sparrow/utils/ranges.hpp
"
20
21
namespace
sparrow::detail
22
{
23
// Functor to get the value of the layout at index i.
24
//
25
// This is usefull to create a iterator over the values of a layout.
26
// This functor will be passed to the functor_index_iterator.
27
template
<
class
LAYOUT_TYPE,
class
VALUE_TYPE>
28
class
layout_value_functor
29
{
30
public
:
31
32
using
value_type
= VALUE_TYPE;
33
using
layout_type
= LAYOUT_TYPE;
34
35
constexpr
explicit
layout_value_functor
(
layout_type
* layout_ =
nullptr
)
36
: p_layout(layout_)
37
{
38
}
39
40
[[nodiscard]]
constexpr
value_type
operator()
(std::size_t i)
const
41
{
42
return
this->p_layout->value(i);
43
}
44
45
private
:
46
47
layout_type
* p_layout;
48
};
49
50
// Functor to get the optional-value of the layout at index i.
51
//
52
// This is usefull to create a iterator over the nullable-values of a layout.
53
// This functor will be passed to the functor_index_iterator.
54
template
<
class
LAYOUT_TYPE,
class
VALUE_TYPE>
55
class
layout_bracket_functor
56
{
57
public
:
58
59
using
value_type
= VALUE_TYPE;
60
using
layout_type
= LAYOUT_TYPE;
61
62
constexpr
explicit
layout_bracket_functor
(
layout_type
* layout_ =
nullptr
)
63
: p_layout(layout_)
64
{
65
}
66
67
constexpr
value_type
operator()
(std::size_t i)
const
68
{
69
return
this->p_layout->operator[](i);
70
}
71
72
private
:
73
74
layout_type
* p_layout;
75
};
76
77
template
<layout_offset OFFSET_TYPE, std::ranges::range SIZES_RANGE>
78
requires
(std::unsigned_integral<std::ranges::range_value_t<SIZES_RANGE>>)
79
[[nodiscard]]
constexpr
sparrow::u8_buffer<OFFSET_TYPE>
offset_buffer_from_sizes
(SIZES_RANGE&& sizes)
80
{
81
sparrow::u8_buffer<OFFSET_TYPE>
buffer
(
range_size
(sizes) + 1);
82
83
OFFSET_TYPE offset = 0;
84
auto
it =
buffer
.
begin
();
85
for
(
auto
size : sizes)
86
{
87
*it = offset;
88
offset +=
static_cast<
OFFSET_TYPE
>
(size);
89
++it;
90
}
91
*it = offset;
92
return
buffer
;
93
}
94
95
}
// namespace sparrow
sparrow::buffer
Object that owns a piece of contiguous memory.
Definition
buffer.hpp:131
sparrow::buffer::begin
constexpr iterator begin() noexcept
Definition
buffer.hpp:680
sparrow::detail::layout_bracket_functor::operator()
constexpr value_type operator()(std::size_t i) const
Definition
layout_utils.hpp:67
sparrow::detail::layout_bracket_functor::layout_type
LAYOUT_TYPE layout_type
Definition
layout_utils.hpp:60
sparrow::detail::layout_bracket_functor::value_type
VALUE_TYPE value_type
Definition
layout_utils.hpp:59
sparrow::detail::layout_bracket_functor::layout_bracket_functor
constexpr layout_bracket_functor(layout_type *layout_=nullptr)
Definition
layout_utils.hpp:62
sparrow::detail::layout_value_functor::operator()
constexpr value_type operator()(std::size_t i) const
Definition
layout_utils.hpp:40
sparrow::detail::layout_value_functor::layout_value_functor
constexpr layout_value_functor(layout_type *layout_=nullptr)
Definition
layout_utils.hpp:35
sparrow::detail::layout_value_functor< array_type, inner_reference >::value_type
inner_reference value_type
Definition
layout_utils.hpp:32
sparrow::detail::layout_value_functor< array_type, inner_reference >::layout_type
array_type layout_type
Definition
layout_utils.hpp:33
sparrow::u8_buffer
This buffer class is used as storage buffer for all sparrow arrays.
Definition
u8_buffer.hpp:116
data_type.hpp
sparrow::detail
Definition
dynamic_bitset.hpp:391
sparrow::detail::offset_buffer_from_sizes
constexpr sparrow::u8_buffer< OFFSET_TYPE > offset_buffer_from_sizes(SIZES_RANGE &&sizes)
Definition
layout_utils.hpp:79
sparrow::range_size
constexpr std::size_t range_size(R &&r)
Definition
ranges.hpp:35
ranges.hpp
u8_buffer.hpp
sparrow
layout
layout_utils.hpp
Generated by
1.17.0