Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion croaring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ criterion = { version = "0.8", features = ["html_reports"] }
[dependencies]
# Support for allocators that use allocator-api2
allocator-api2 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] }
ffi = { package = "croaring-sys", path = "../croaring-sys", version = "4.4.0" }
ffi = { package = "croaring-sys", path = "../croaring-sys", version = "4.6.1" }

[[bench]]
name = "benches"
Expand Down
57 changes: 57 additions & 0 deletions croaring/src/bitmap64/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,28 @@ impl Bitmap64 {
unsafe { ffi::roaring64_bitmap_run_optimize(self.raw.as_ptr()) }
}

/// Remove run-length encoding even when it is more space efficient
///
/// Returns true if a change was applied
///
/// # Examples
///
/// ```
/// use croaring::Bitmap64;
///
/// let mut bitmap: Bitmap64 = (100..1000).collect();
///
/// bitmap.run_optimize();
///
/// assert!(bitmap.remove_run_compression());
/// assert!(!bitmap.remove_run_compression());
/// ```
#[inline]
#[doc(alias = "roaring64_bitmap_remove_run_compression")]
pub fn remove_run_compression(&mut self) -> bool {
unsafe { ffi::roaring64_bitmap_remove_run_compression(self.raw.as_ptr()) }
}

/// Returns true if the element is contained in the bitmap
///
/// # Examples
Expand Down Expand Up @@ -755,6 +777,41 @@ impl Bitmap64 {
unsafe { ffi::roaring64_bitmap_flip_closed_inplace(self.raw.as_ptr(), start, end) };
}

/// Returns a new bitmap with all values shifted by the given offset
///
/// Any values which would underflow or overflow `u64` are dropped.
///
/// # Examples
/// ```
/// use croaring::Bitmap64;
///
/// let bitmap1 = Bitmap64::of(&[0, 1, 1000, u64::MAX]);
/// let shifted_down = bitmap1.add_offset(-1);
/// assert_eq!(shifted_down.iter().collect::<Vec<_>>(), [0, 999, u64::MAX - 1]);
/// let shifted_up = bitmap1.add_offset(1);
/// assert_eq!(shifted_up.iter().collect::<Vec<_>>(), [1, 2, 1001]);
/// let big_shifted = bitmap1.add_offset(i128::from(u64::MAX) + 1);
/// assert_eq!(big_shifted.iter().collect::<Vec<_>>(), []);
/// ```
#[inline]
#[doc(alias = "roaring64_bitmap_add_offset_signed")]
#[must_use]
pub fn add_offset(&self, offset: i128) -> Self {
let positive = offset >= 0;
let offset = offset.unsigned_abs();
let Ok(offset) = u64::try_from(offset) else {
// If the offset doesn't fit in 64 bits, we shifted everything out
return Self::new();
};
unsafe {
Self::take_heap(ffi::roaring64_bitmap_add_offset_signed(
self.raw.as_ptr(),
positive,
offset,
))
}
}

/// Returns a vector containing the values in the bitmap in sorted order
///
/// # Examples
Expand Down
8 changes: 8 additions & 0 deletions croaring/src/bitmap64/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ impl Clone for Bitmap64 {
Self::take_heap(raw)
}
}

#[inline]
#[doc(alias = "roaring64_bitmap_overwrite")]
fn clone_from(&mut self, source: &Self) {
unsafe {
ffi::roaring64_bitmap_overwrite(self.raw.as_ptr(), source.raw.as_ptr());
}
}
}

impl Drop for Bitmap64 {
Expand Down