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#include <vector>
32
34#include "iceberg/result.h"
35
36namespace iceberg {
37
38class PositionDeleteIndex;
39
48
52class ICEBERG_EXPORT RoaringPositionBitmap {
53 public:
55 static constexpr int64_t kMaxPosition = 0x7FFFFFFE80000000LL;
56
59
61 RoaringPositionBitmap& operator=(RoaringPositionBitmap&& other) noexcept;
62
64 RoaringPositionBitmap& operator=(const RoaringPositionBitmap& other);
65
69 void Add(int64_t pos);
70
77 void AddRange(int64_t pos_start, int64_t pos_end);
78
82 bool Contains(int64_t pos) const;
83
85 bool IsEmpty() const;
86
88 size_t Cardinality() const;
89
92 void Or(const RoaringPositionBitmap& other);
93
98 bool Optimize();
99
101 void ForEach(const std::function<void(int64_t)>& fn) const;
102
104 size_t SerializedSizeInBytes() const;
105
108
110 static Result<RoaringPositionBitmap> Deserialize(std::string_view bytes);
111
112 private:
113 struct Impl;
114 std::unique_ptr<Impl> impl_;
115
116 explicit RoaringPositionBitmap(std::unique_ptr<Impl> impl);
117
118 // Bulk-add positions sharing high-32-bit `key`. Internal hook for
119 // `PositionDeleteIndex::BulkAddForKey`; per-key grouping is the caller's
120 // job, keeping this a thin wrapper around CRoaring's `addMany`.
121 void AddManyForKey(int32_t key, std::span<const uint32_t> positions);
122 // Appends the portable serialized bitmap and returns bytes appended.
123 Result<size_t> SerializeTo(std::vector<uint8_t>& output) const;
124 friend class PositionDeleteIndex;
125};
126
127} // namespace iceberg
Tracks deleted row positions using a bitmap.
Definition position_delete_index.h:42
A bitmap that supports positive 64-bit positions, optimized for cases where most positions fit in 32 ...
Definition roaring_position_bitmap.h:52
void ForEach(const std::function< void(int64_t)> &fn) const
Iterates over all set positions in ascending order.
void Add(int64_t pos)
Sets a position in the bitmap.
Result< std::string > Serialize() const
Serializes using the portable format (little-endian).
size_t Cardinality() const
Returns the number of set positions in the bitmap.
void Or(const RoaringPositionBitmap &other)
Merges all positions from the other bitmap into this one (in-place union).
void AddRange(int64_t pos_start, int64_t pos_end)
Sets a range of positions [pos_start, pos_end).
bool Contains(int64_t pos) const
Checks if a position is set in the bitmap.
static Result< RoaringPositionBitmap > Deserialize(std::string_view bytes)
Deserializes a bitmap from bytes.
bool IsEmpty() const
Returns true if the bitmap has no positions set.
bool Optimize()
Optimizes the bitmap by applying run-length encoding to containers where it is more space efficient t...
size_t SerializedSizeInBytes() const
Returns the serialized size in bytes.
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.