]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/parquet/level_comparison_inc.h
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
19 #include "arrow/util/bit_util.h"
20 #include "arrow/util/endian.h"
21 #include "parquet/level_comparison.h"
23 // Used to make sure ODR rule isn't violated.
24 #ifndef PARQUET_IMPL_NAMESPACE
25 #error "PARQUET_IMPL_NAMESPACE must be defined"
29 namespace PARQUET_IMPL_NAMESPACE
{
30 /// Builds a bitmap by applying predicate to the level vector provided.
32 /// \param[in] levels Rep or def level array.
33 /// \param[in] num_levels The number of levels to process (must be [0, 64])
34 /// \param[in] predicate The predicate to apply (must have the signature `bool
35 /// predicate(int16_t)`.
36 /// \returns The bitmap using least significant "bit" ordering.
38 template <typename Predicate
>
39 inline uint64_t LevelsToBitmap(const int16_t* levels
, int64_t num_levels
,
40 Predicate predicate
) {
41 // Both clang and GCC can vectorize this automatically with SSE4/AVX2.
43 for (int x
= 0; x
< num_levels
; x
++) {
44 mask
|= static_cast<uint64_t>(predicate(levels
[x
]) ? 1 : 0) << x
;
46 return ::arrow::BitUtil::ToLittleEndian(mask
);
49 inline MinMax
FindMinMaxImpl(const int16_t* levels
, int64_t num_levels
) {
50 MinMax out
{std::numeric_limits
<int16_t>::max(), std::numeric_limits
<int16_t>::min()};
51 for (int x
= 0; x
< num_levels
; x
++) {
52 out
.min
= std::min(levels
[x
], out
.min
);
53 out
.max
= std::max(levels
[x
], out
.max
);
58 inline uint64_t GreaterThanBitmapImpl(const int16_t* levels
, int64_t num_levels
,
60 return LevelsToBitmap(levels
, num_levels
, [rhs
](int16_t value
) { return value
> rhs
; });
63 } // namespace PARQUET_IMPL_NAMESPACE
64 } // namespace internal
65 } // namespace parquet