@@ -527,6 +527,28 @@ impl Bitmap64 {
527527 unsafe { ffi:: roaring64_bitmap_run_optimize ( self . raw . as_ptr ( ) ) }
528528 }
529529
530+ /// Remove run-length encoding even when it is more space efficient
531+ ///
532+ /// Returns true if a change was applied
533+ ///
534+ /// # Examples
535+ ///
536+ /// ```
537+ /// use croaring::Bitmap64;
538+ ///
539+ /// let mut bitmap: Bitmap64 = (100..1000).collect();
540+ ///
541+ /// bitmap.run_optimize();
542+ ///
543+ /// assert!(bitmap.remove_run_compression());
544+ /// assert!(!bitmap.remove_run_compression());
545+ /// ```
546+ #[ inline]
547+ #[ doc( alias = "roaring64_bitmap_remove_run_compression" ) ]
548+ pub fn remove_run_compression ( & mut self ) -> bool {
549+ unsafe { ffi:: roaring64_bitmap_remove_run_compression ( self . raw . as_ptr ( ) ) }
550+ }
551+
530552 /// Returns true if the element is contained in the bitmap
531553 ///
532554 /// # Examples
@@ -755,6 +777,41 @@ impl Bitmap64 {
755777 unsafe { ffi:: roaring64_bitmap_flip_closed_inplace ( self . raw . as_ptr ( ) , start, end) } ;
756778 }
757779
780+ /// Returns a new bitmap with all values shifted by the given offset
781+ ///
782+ /// Any values which would underflow or overflow `u64` are dropped.
783+ ///
784+ /// # Examples
785+ /// ```
786+ /// use croaring::Bitmap64;
787+ ///
788+ /// let bitmap1 = Bitmap64::of(&[0, 1, 1000, u64::MAX]);
789+ /// let shifted_down = bitmap1.add_offset(-1);
790+ /// assert_eq!(shifted_down.iter().collect::<Vec<_>>(), [0, 999, u64::MAX - 1]);
791+ /// let shifted_up = bitmap1.add_offset(1);
792+ /// assert_eq!(shifted_up.iter().collect::<Vec<_>>(), [1, 2, 1001]);
793+ /// let big_shifted = bitmap1.add_offset(i128::from(u64::MAX) + 1);
794+ /// assert_eq!(big_shifted.iter().collect::<Vec<_>>(), []);
795+ /// ```
796+ #[ inline]
797+ #[ doc( alias = "roaring64_bitmap_add_offset_signed" ) ]
798+ #[ must_use]
799+ pub fn add_offset ( & self , offset : i128 ) -> Self {
800+ let positive = offset >= 0 ;
801+ let offset = offset. unsigned_abs ( ) ;
802+ let Ok ( offset) = u64:: try_from ( offset) else {
803+ // If the offset doesn't fit in 64 bits, we shifted everything out
804+ return Self :: new ( ) ;
805+ } ;
806+ unsafe {
807+ Self :: take_heap ( ffi:: roaring64_bitmap_add_offset_signed (
808+ self . raw . as_ptr ( ) ,
809+ positive,
810+ offset,
811+ ) )
812+ }
813+ }
814+
758815 /// Returns a vector containing the values in the bitmap in sorted order
759816 ///
760817 /// # Examples
0 commit comments