sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
offsets.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
#include <numeric>
16
#include <ranges>
17
18
#include "
sparrow/buffer/buffer.hpp
"
19
#include "
sparrow/types/data_type.hpp
"
20
21
#pragma once
22
23
namespace
sparrow
24
{
25
template
<layout_offset OT, std::ranges::sized_range R>
26
requires
std::ranges::sized_range<std::ranges::range_value_t<R>>
27
[[nodiscard]]
constexpr
buffer<OT>
make_offset_buffer
(
const
R& range)
28
{
29
const
size_t
range_size
= std::ranges::size(range);
30
buffer<OT>
offsets(
range_size
+ 1, 0,
typename
buffer<OT>::default_allocator
());
31
std::transform(
32
range.cbegin(),
33
range.cend(),
34
offsets.
begin
() + 1,
35
[](
const
auto
& elem)
36
{
37
return static_cast<OT>(elem.size());
38
}
39
);
40
std::partial_sum(offsets.
begin
(), offsets.
end
(), offsets.
begin
());
41
return
offsets;
42
}
43
}
buffer.hpp
sparrow::buffer
Object that owns a piece of contiguous memory.
Definition
buffer.hpp:131
sparrow::buffer::default_allocator
xsimd::aligned_allocator< T > default_allocator
Definition
buffer.hpp:144
sparrow::buffer::begin
constexpr iterator begin() noexcept
Definition
buffer.hpp:680
sparrow::buffer::end
constexpr iterator end() noexcept
Definition
buffer.hpp:686
data_type.hpp
sparrow
Definition
array.hpp:21
sparrow::range_size
constexpr std::size_t range_size(R &&r)
Definition
ranges.hpp:35
sparrow::make_offset_buffer
constexpr buffer< OT > make_offset_buffer(const R &range)
Definition
offsets.hpp:27
sparrow
utils
offsets.hpp
Generated by
1.17.0