Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add From<Bitmap> for Bitmap64 #157

Merged
merged 2 commits into from
Sep 20, 2024
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 @@ -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),
}
});
Loading