Skip to content

Commit 3b0ced1

Browse files
authored
Merge pull request #86 from Dr-Emann/bump_croaring
Bump croaring to 0.5.0
2 parents 040cfab + 3f108cc commit 3b0ced1

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

croaring/src/bitmap/imp.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ impl Bitmap {
1919
// the version of croaring.
2020
const _: () = assert!(
2121
ffi::ROARING_VERSION_MAJOR == 0
22-
&& ffi::ROARING_VERSION_MINOR == 3
23-
&& ffi::ROARING_VERSION_REVISION == 4
22+
&& ffi::ROARING_VERSION_MINOR == 5
23+
&& ffi::ROARING_VERSION_REVISION == 0
2424
);
25-
// When changing roaring version, check if this should use `roaring_free` instead
26-
libc::free(p as *mut _);
25+
ffi::roaring_free(p as *mut _);
2726
result
2827
}
2928

@@ -288,6 +287,27 @@ impl Bitmap {
288287
unsafe { ffi::roaring_bitmap_contains(&self.bitmap, element) }
289288
}
290289

290+
/// Compute a new bitmap, which contains all values from this bitmap, but shifted by `offset`
291+
///
292+
/// Any values which would be `< 0`, or `> u32::MAX` are dropped.
293+
///
294+
/// # Examples
295+
/// ```
296+
/// use croaring::Bitmap;
297+
///
298+
/// let bitmap1 = Bitmap::of(&[0, 1, 1000, u32::MAX]);
299+
/// let shifted_down = bitmap1.add_offset(-1);
300+
/// assert_eq!(shifted_down.to_vec(), [0, 999, u32::MAX - 1]);
301+
/// let shifted_up = bitmap1.add_offset(1);
302+
/// assert_eq!(shifted_up.to_vec(), [1, 2, 1001]);
303+
/// let big_shifted = bitmap1.add_offset(i64::from(u32::MAX) + 1);
304+
/// assert_eq!(big_shifted.to_vec(), []);
305+
/// ```
306+
#[inline]
307+
pub fn add_offset(&self, offset: i64) -> Self {
308+
unsafe { Bitmap::take_heap(ffi::roaring_bitmap_add_offset(&self.bitmap, offset)) }
309+
}
310+
291311
/// Returns number of elements in range
292312
///
293313
/// # Examples

croaring/src/bitmap/ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl Drop for Bitmap {
6767
// Ensure this is still valid every time we update the version of croaring.
6868
const _: () = assert!(
6969
ffi::ROARING_VERSION_MAJOR == 0
70-
&& ffi::ROARING_VERSION_MINOR == 3
71-
&& ffi::ROARING_VERSION_REVISION == 4
70+
&& ffi::ROARING_VERSION_MINOR == 5
71+
&& ffi::ROARING_VERSION_REVISION == 0
7272
);
7373

7474
// Per https://github.com/RoaringBitmap/CRoaring/blob/4f8dbdb0cc884626b20ef0cc9e891f701fe157cf/cpp/roaring.hh#L182

0 commit comments

Comments
 (0)