iceberg-cpp
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
iceberg::RoaringPositionBitmap Class Reference

A bitmap that supports positive 64-bit positions, optimized for cases where most positions fit in 32 bits. More...

#include <roaring_position_bitmap.h>

Classes

struct  Impl
 

Public Member Functions

 RoaringPositionBitmap (RoaringPositionBitmap &&other) noexcept
 
RoaringPositionBitmapoperator= (RoaringPositionBitmap &&other) noexcept
 
 RoaringPositionBitmap (const RoaringPositionBitmap &other)
 
RoaringPositionBitmapoperator= (const RoaringPositionBitmap &other)
 
void Add (int64_t pos)
 Sets a position in the bitmap.
 
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.
 
bool IsEmpty () const
 Returns true if the bitmap has no positions set.
 
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).
 
bool Optimize ()
 Optimizes the bitmap by applying run-length encoding to containers where it is more space efficient than array or bitset representations.
 
void ForEach (const std::function< void(int64_t)> &fn) const
 Iterates over all set positions in ascending order.
 
size_t SerializedSizeInBytes () const
 Returns the serialized size in bytes.
 
Result< std::string > Serialize () const
 Serializes using the portable format (little-endian).
 

Static Public Member Functions

static Result< RoaringPositionBitmapDeserialize (std::string_view bytes)
 Deserializes a bitmap from bytes.
 

Static Public Attributes

static constexpr int64_t kMaxPosition = 0x7FFFFFFE80000000LL
 Maximum supported position (aligned with the Java implementation).
 

Detailed Description

A bitmap that supports positive 64-bit positions, optimized for cases where most positions fit in 32 bits.

Incoming 64-bit positions are divided into a 32-bit "key" using the most significant 4 bytes and a 32-bit position using the least significant 4 bytes. For each key, a 32-bit Roaring bitmap is maintained to store positions for that key.

Note
This class is used to represent deletion vectors. The Puffin reader/writer handle adding the additional required framing (length prefix, magic bytes, CRC-32) for deletion-vector-v1 persistence.

Member Function Documentation

◆ Add()

void iceberg::RoaringPositionBitmap::Add ( int64_t  pos)

Sets a position in the bitmap.

Parameters
posthe position (must be >= 0 and <= kMaxPosition)
Note
Invalid positions are silently ignored

◆ AddRange()

void iceberg::RoaringPositionBitmap::AddRange ( int64_t  pos_start,
int64_t  pos_end 
)

Sets a range of positions [pos_start, pos_end).

Parameters
pos_startthe start of the range (inclusive), clamped to 0
pos_endthe end of the range (exclusive), clamped to kMaxPosition + 1
Note
If pos_start > pos_end, the call is silently ignored. If pos_start == pos_end, this method does nothing. Positions outside [0, kMaxPosition] are silently ignored.

◆ Contains()

bool iceberg::RoaringPositionBitmap::Contains ( int64_t  pos) const

Checks if a position is set in the bitmap.

Parameters
posthe position to check
Returns
true if the position is set, false otherwise (including invalid positions)

◆ Optimize()

bool iceberg::RoaringPositionBitmap::Optimize ( )

Optimizes the bitmap by applying run-length encoding to containers where it is more space efficient than array or bitset representations.

Returns
true if any container was changed

The documentation for this class was generated from the following files: