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

Use new croaring funcs #141

Merged
merged 2 commits into from
Jul 8, 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
24 changes: 4 additions & 20 deletions croaring/src/bitmap64/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ impl Bitmap64 {
/// assert!(bitmap.is_empty());
/// ```
#[inline]
#[doc(alias = "roaring64_bitmap_clear")]
pub fn clear(&mut self) {
self.remove_range(..);
unsafe { ffi::roaring64_bitmap_clear(self.raw.as_ptr()) }
}

/// Returns the number of values in the bitmap
Expand Down Expand Up @@ -385,25 +386,8 @@ impl Bitmap64 {
#[must_use]
#[doc(alias = "roaring64_bitmap_range_cardinality")]
pub fn range_cardinality<R: RangeBounds<u64>>(&self, range: R) -> u64 {
let Some(exclusive_range) = range_to_exclusive(range) else {
return 0;
};
self._range_cardinality(exclusive_range)
}

#[inline]
fn _range_cardinality(&self, exclusive_range: ExclusiveRangeRes) -> u64 {
let ExclusiveRangeRes {
start,
end,
needs_max,
} = exclusive_range;
let mut cardinality =
unsafe { ffi::roaring64_bitmap_range_cardinality(self.raw.as_ptr(), start, end) };
if needs_max {
cardinality += u64::from(self.contains(u64::MAX));
}
cardinality
let (start, end) = range_to_inclusive(range);
unsafe { ffi::roaring64_bitmap_range_closed_cardinality(self.raw.as_ptr(), start, end) }
}

/// Returns true if the bitmap is empty
Expand Down
7 changes: 6 additions & 1 deletion croaring/src/treemap/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,13 @@ impl Serializer for JvmLegacy {
let bitmap_count: u32 = treemap.map.len().try_into().unwrap();
dst.extend_from_slice(&bitmap_count.to_be_bytes());
treemap.map.iter().for_each(|(&key, bitmap)| {
fn assert_unaligned<S: crate::serialization::NoAlign>() {}
dst.extend_from_slice(&key.to_be_bytes());
bitmap.serialize_into_vec::<Portable>(dst);

// Because Portable serialization doesn't require alignment,
// we know serializing into a vec will not leave any padding before the serialized data
assert_unaligned::<Portable>();
let _ = bitmap.serialize_into_vec::<Portable>(dst);
});

&dst[start_idx..]
Expand Down
15 changes: 8 additions & 7 deletions fuzz/fuzz_targets/against_bitvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ impl ReadBitmapOp {
assert_eq!(v.count_ones() as u64, b.cardinality());
}
ReadBitmapOp::Flip(ref r) => {
b.flip(r.start().0..=r.end().0);
_ = b.flip(r.start().0..=r.end().0);
}
ReadBitmapOp::ToVec => {
let vec_iter = b.to_vec();
assert!(vec_iter.into_iter().eq(v.iter_ones().map(|i| i as u32)));
}
ReadBitmapOp::GetPortableSerializedSizeInBytes => {
b.get_serialized_size_in_bytes::<Portable>();
_ = b.get_serialized_size_in_bytes::<Portable>();
}
ReadBitmapOp::GetNativeSerializedSizeInBytes => {
b.get_serialized_size_in_bytes::<Native>();
_ = b.get_serialized_size_in_bytes::<Native>();
}
ReadBitmapOp::GetFrozenSerializedSizeInBytes => {
b.get_serialized_size_in_bytes::<Frozen>();
_ = b.get_serialized_size_in_bytes::<Frozen>();
}
ReadBitmapOp::IsEmpty => {
assert_eq!(v.not_any(), b.is_empty());
Expand Down Expand Up @@ -121,7 +121,7 @@ impl ReadBitmapOp {
);
}
ReadBitmapOp::Statistics => {
b.statistics();
_ = b.statistics();
}
ReadBitmapOp::Clone => {
drop(b.clone());
Expand All @@ -142,13 +142,14 @@ impl ReadBitmapOp {
}
IterOperation::NextMany(n) => {
let mut v = vec![0; n as usize];
iter.next_many(&mut v);
let res = iter.next_many(&mut v);
assert!(res <= n as usize);
}
}
}
}
ReadBitmapOp::AddOffset(i) => {
b.add_offset(i);
_ = b.add_offset(i);
}
}
b.internal_validate().unwrap();
Expand Down
10 changes: 5 additions & 5 deletions fuzz/fuzz_targets/arbitrary_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ impl BitmapCompOperation {
assert_eq!(lhs, lhs);
}
BitmapCompOperation::IsSubset => {
lhs.is_subset(rhs);
_ = lhs.is_subset(rhs);
assert!(lhs.is_subset(lhs));
}
BitmapCompOperation::IsStrictSubset => {
lhs.is_strict_subset(rhs);
_ = lhs.is_strict_subset(rhs);
assert!(!lhs.is_strict_subset(lhs));
}
BitmapCompOperation::Intersect => {
lhs.intersect(rhs);
_ = lhs.intersect(rhs);
assert!(lhs.is_empty() || lhs.intersect(lhs));
}
BitmapCompOperation::JacardIndex => {
lhs.jaccard_index(rhs);
lhs.jaccard_index(lhs);
_ = lhs.jaccard_index(rhs);
_ = lhs.jaccard_index(lhs);
}
BitmapCompOperation::And => {
assert_eq!(lhs.and(lhs), *lhs);
Expand Down
32 changes: 16 additions & 16 deletions fuzz/fuzz_targets/fuzz_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,55 +66,55 @@ impl ReadBitmapOp {
pub fn on_roaring(&self, b: &Bitmap) {
match *self {
ReadBitmapOp::ContainsRange(ref r) => {
b.contains_range(r.start().0..=r.end().0);
let _ = b.contains_range(r.start().0..=r.end().0);
}
ReadBitmapOp::Contains(i) => {
b.contains(i.0);
let _ = b.contains(i.0);
}
ReadBitmapOp::RangeCardinality(ref r) => {
b.range_cardinality(r.start().0..=r.end().0);
let _ = b.range_cardinality(r.start().0..=r.end().0);
}
ReadBitmapOp::Cardinality => {
b.cardinality();
let _ = b.cardinality();
}
ReadBitmapOp::Flip(ref r) => {
b.flip(r.start().0..=r.end().0);
let _ = b.flip(r.start().0..=r.end().0);
}
ReadBitmapOp::ToVec => {
drop(b.to_vec());
}
ReadBitmapOp::GetPortableSerializedSizeInBytes => {
b.get_serialized_size_in_bytes::<Portable>();
let _ = b.get_serialized_size_in_bytes::<Portable>();
}
ReadBitmapOp::GetNativeSerializedSizeInBytes => {
b.get_serialized_size_in_bytes::<Native>();
let _ = b.get_serialized_size_in_bytes::<Native>();
}
ReadBitmapOp::GetFrozenSerializedSizeInBytes => {
b.get_serialized_size_in_bytes::<Frozen>();
let _ = b.get_serialized_size_in_bytes::<Frozen>();
}
ReadBitmapOp::IsEmpty => {
assert_eq!(b.is_empty(), b.cardinality() == 0);
}
ReadBitmapOp::IntersectWithRange(ref r) => {
b.intersect_with_range(r.start().0..=r.end().0);
let _ = b.intersect_with_range(r.start().0..=r.end().0);
}
ReadBitmapOp::Minimum => {
b.minimum();
let _ = b.minimum();
}
ReadBitmapOp::Maximum => {
b.maximum();
let _ = b.maximum();
}
ReadBitmapOp::Rank(i) => {
b.rank(i.0);
let _ = b.rank(i.0);
}
ReadBitmapOp::Index(i) => {
b.position(i.0);
let _ = b.position(i.0);
}
ReadBitmapOp::Select(i) => {
b.select(i.0);
let _ = b.select(i.0);
}
ReadBitmapOp::Statistics => {
b.statistics();
let _ = b.statistics();
}
ReadBitmapOp::Clone => {
drop(b.clone());
Expand All @@ -141,7 +141,7 @@ impl ReadBitmapOp {
}
}
ReadBitmapOp::AddOffset(i) => {
b.add_offset(i);
let _ = b.add_offset(i);
}
}
}
Expand Down
Loading