Skip to content

Commit

Permalink
Add From<Bitmap> for Bitmap64 (#157)
Browse files Browse the repository at this point in the history
Use new roaring64_bitmap_move_from_roaring32 function
  • Loading branch information
Dr-Emann authored Sep 20, 2024
2 parents 5c85403 + 0bcef52 commit 7716f57
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion croaring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ roaring = "0.10"
criterion = { version = "0.5", features = ["html_reports"] }

[dependencies]
ffi = { package = "croaring-sys", path = "../croaring-sys", version = "~4.1.1" }
ffi = { package = "croaring-sys", path = "../croaring-sys", version = "~4.1.4" }

[[bench]]
name = "benches"
Expand Down
2 changes: 1 addition & 1 deletion croaring/src/bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use core::marker::PhantomData;
// &BitmapView and &Bitmap
#[repr(transparent)]
pub struct Bitmap {
bitmap: ffi::roaring_bitmap_t,
pub(crate) bitmap: ffi::roaring_bitmap_t,
}

unsafe impl Sync for Bitmap {}
Expand Down
8 changes: 7 additions & 1 deletion croaring/src/bitmap64/ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Bitmap64;
use crate::{Bitmap, Bitmap64};
use core::fmt;
use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign};
use ffi::roaring64_bitmap_copy;
Expand Down Expand Up @@ -45,6 +45,12 @@ impl From<&'_ [u64]> for Bitmap64 {
}
}

impl From<Bitmap> for Bitmap64 {
fn from(mut value: Bitmap) -> Self {
unsafe { Self::take_heap(ffi::roaring64_bitmap_move_from_roaring32(&mut value.bitmap)) }
}
}

impl<const N: usize> From<[u64; N]> for Bitmap64 {
#[inline]
#[doc(alias = "roaring64_bitmap_of_ptr")]
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions fuzz/fuzz_targets/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use croaring::{Bitmap, Bitmap64, Native, Portable};
use libfuzzer_sys::fuzz_target;
use libfuzzer_sys::arbitrary::{self, Arbitrary};

fn check_bitmap<D: croaring::bitmap::Deserializer>(input: &[u8]) {
let bitmap = Bitmap::try_deserialize::<D>(input);
Expand Down Expand Up @@ -63,8 +64,18 @@ fn check_bitmap64<D: croaring::bitmap64::Deserializer>(input: &[u8]) {
}
}

fuzz_target!(|input: &[u8]| {
check_bitmap::<Portable>(input);
check_bitmap::<Native>(input);
check_bitmap64::<Portable>(input);
#[derive(Arbitrary, Debug)]
enum BitmapType {
Portable32,
Native32,
Portable64,
}

fuzz_target!(|input: (BitmapType, &[u8])| {
let (ty, input) = input;
match ty {
BitmapType::Portable32 => check_bitmap::<Portable>(input),
BitmapType::Native32 => check_bitmap::<Native>(input),
BitmapType::Portable64 => check_bitmap64::<Portable>(input),
}
});

0 comments on commit 7716f57

Please sign in to comment.