iceberg-cpp
Loading...
Searching...
No Matches
roaring_position_bitmap.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <span>
29#include <string>
30#include <string_view>
31
32#include "iceberg/iceberg_data_export.h"
33#include "iceberg/result.h"
34
35namespace iceberg {
36
37class PositionDeleteIndex;
38
47
51class ICEBERG_DATA_EXPORT RoaringPositionBitmap {
52 public:
54 static constexpr int64_t kMaxPosition = 0x7FFFFFFE80000000LL;
55
58
60 RoaringPositionBitmap& operator=(RoaringPositionBitmap&& other) noexcept;
61
63 RoaringPositionBitmap& operator=(const RoaringPositionBitmap& other);
64
68 void Add(int64_t pos);
69
76 void AddRange(int64_t pos_start, int64_t pos_end);
77
81 bool Contains(int64_t pos) const;
82
84 bool IsEmpty() const;
85
87 size_t Cardinality() const;
88
91 void Or(const RoaringPositionBitmap& other);
92
97 bool Optimize();
98
100 void ForEach(const std::function<void(int64_t)>& fn) const;
101
103 size_t SerializedSizeInBytes() const;
104
106 Result<std::string> Serialize() const;
107
109 static Result<RoaringPositionBitmap> Deserialize(std::string_view bytes);
110
111 private:
112 struct Impl;
113 std::unique_ptr<Impl> impl_;
114
115 explicit RoaringPositionBitmap(std::unique_ptr<Impl> impl);
116
117 // Bulk-add positions sharing high-32-bit `key`. Internal hook for
118 // `PositionDeleteIndex::BulkAddForKey`; per-key grouping is the caller's
119 // job, keeping this a thin wrapper around CRoaring's `addMany`.
120 void AddManyForKey(int32_t key, std::span<const uint32_t> positions);
121 friend class PositionDeleteIndex;
122};
123
124} // namespace iceberg
An Expression that represents a logical OR operation between two expressions.
Definition expression.h:215
Tracks deleted row positions using a bitmap.
Definition position_delete_index.h:40
A bitmap that supports positive 64-bit positions, optimized for cases where most positions fit in 32 ...
Definition roaring_position_bitmap.h:51
Definition roaring_position_bitmap.cc:62