Skip to content

Commit f24bf2f

Browse files
committed
switch croaring to edition 2024
add a msrv of 1.95
1 parent 224e1e8 commit f24bf2f

17 files changed

Lines changed: 269 additions & 221 deletions

File tree

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [ubuntu-latest, windows-latest, macos-latest]
18-
rust: [stable, nightly]
18+
rust: ["1.95", stable, nightly]
1919
cargo_features: ['', 'alloc', 'default']
2020

2121
env:

croaring/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "croaring"
33
version = "2.6.0"
4-
edition = "2021"
4+
edition = "2024"
55
authors = ["croaring-rs developers"]
66
license = "Apache-2.0"
77
description = "Rust wrapper for CRoaring"
@@ -10,6 +10,7 @@ readme = "../README.md"
1010
keywords = ["RoaringBitmap", "croaring", "bitmap"]
1111
categories = ["data-structures", "api-bindings", "no-std::no-alloc"]
1212
documentation = "https://docs.rs/croaring"
13+
rust-version = "1.95.0"
1314

1415
[features]
1516
default = ["std", "allocator-api2"]

croaring/benches/benches.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use criterion::{
2-
black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput,
3-
};
1+
use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
2+
use std::hint::black_box;
43
use std::ops::ControlFlow;
54

65
use croaring::{Bitmap, Bitmap64, Portable};

croaring/benches/performance_comparison.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use croaring::Bitmap;
22
use roaring::RoaringBitmap;
3+
use std::hint::black_box;
34

45
use criterion::measurement::Measurement;
56
use criterion::{
6-
black_box, criterion_group, criterion_main, BatchSize, BenchmarkGroup, BenchmarkId, Criterion,
7+
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, criterion_group, criterion_main,
78
};
89

910
fn compare<Prep1, Prep2, Bench1, Bench2, In1, In2, Out1, Out2, M>(
@@ -151,7 +152,7 @@ fn binops(c: &mut Criterion) {
151152
};
152153

153154
macro_rules! comp_op {
154-
($new1:ident, $inplace1:ident, $new2:expr, $inplace2:expr $(,)?) => {{
155+
($new1:ident, $inplace1:ident, $new2:expr_2021, $inplace2:expr_2021 $(,)?) => {{
155156
compare(
156157
&mut c.benchmark_group(concat!(stringify!($new1), "_new")),
157158
gen_ours,

croaring/src/bitmap/imp.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ impl Bitmap {
1616
#[allow(clippy::assertions_on_constants)]
1717
#[must_use]
1818
pub(crate) unsafe fn take_heap(p: *mut roaring_bitmap_t) -> Self {
19-
// Based heavily on the `roaring.hh` cpp header from croaring
20-
21-
assert!(!p.is_null());
22-
let result = Self { bitmap: *p };
23-
// This depends somewhat heavily on the implementation of croaring,
24-
// In particular, that `roaring_bitmap_t` doesn't store any pointers into itself
25-
// (it can be moved safely), and can be freed with `free`, without freeing the underlying
26-
// containers and auxiliary data. Ensure this is still valid every time we update
27-
// the version of croaring.
28-
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4);
29-
ffi::roaring_free(p.cast::<c_void>());
30-
result
19+
unsafe {
20+
// Based heavily on the `roaring.hh` cpp header from croaring
21+
22+
assert!(!p.is_null());
23+
let result = Self { bitmap: *p };
24+
// This depends somewhat heavily on the implementation of croaring,
25+
// In particular, that `roaring_bitmap_t` doesn't store any pointers into itself
26+
// (it can be moved safely), and can be freed with `free`, without freeing the underlying
27+
// containers and auxiliary data. Ensure this is still valid every time we update
28+
// the version of croaring.
29+
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4);
30+
ffi::roaring_free(p.cast::<c_void>());
31+
result
32+
}
3133
}
3234

3335
/// Creates a new bitmap (initially empty)
@@ -1523,11 +1525,7 @@ impl Bitmap {
15231525
let mut element: u32 = 0;
15241526
let result = unsafe { ffi::roaring_bitmap_select(&self.bitmap, position, &mut element) };
15251527

1526-
if result {
1527-
Some(element)
1528-
} else {
1529-
None
1530-
}
1528+
if result { Some(element) } else { None }
15311529
}
15321530

15331531
/// Returns statistics about the composition of a roaring bitmap.

croaring/src/bitmap/serialization.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ impl Deserializer for Portable {
157157

158158
#[doc(alias = "roaring_bitmap_portable_deserialize")]
159159
unsafe fn try_deserialize_unchecked(buffer: &[u8]) -> Bitmap {
160-
let bitmap = ffi::roaring_bitmap_portable_deserialize(buffer.as_ptr().cast::<c_char>());
161-
Bitmap::take_heap(bitmap)
160+
unsafe {
161+
let bitmap = ffi::roaring_bitmap_portable_deserialize(buffer.as_ptr().cast::<c_char>());
162+
Bitmap::take_heap(bitmap)
163+
}
162164
}
163165
}
164166

@@ -175,13 +177,15 @@ impl ViewDeserializer for Portable {
175177
///
176178
#[doc(alias = "roaring_bitmap_portable_deserialize_frozen")]
177179
unsafe fn deserialize_view(data: &[u8]) -> BitmapView<'_> {
178-
// portable_deserialize_size does some amount of checks, and returns zero if data cannot be valid
179-
debug_assert_ne!(
180-
ffi::roaring_bitmap_portable_deserialize_size(data.as_ptr().cast(), data.len()),
181-
0,
182-
);
183-
let roaring = ffi::roaring_bitmap_portable_deserialize_frozen(data.as_ptr().cast());
184-
BitmapView::take_heap(roaring)
180+
unsafe {
181+
// portable_deserialize_size does some amount of checks, and returns zero if data cannot be valid
182+
debug_assert_ne!(
183+
ffi::roaring_bitmap_portable_deserialize_size(data.as_ptr().cast(), data.len()),
184+
0,
185+
);
186+
let roaring = ffi::roaring_bitmap_portable_deserialize_frozen(data.as_ptr().cast());
187+
BitmapView::take_heap(roaring)
188+
}
185189
}
186190
}
187191

@@ -226,8 +230,10 @@ impl Deserializer for Native {
226230

227231
#[doc(alias = "roaring_bitmap_deserialize")]
228232
unsafe fn try_deserialize_unchecked(buffer: &[u8]) -> Bitmap {
229-
let bitmap = ffi::roaring_bitmap_deserialize(buffer.as_ptr().cast::<c_void>());
230-
Bitmap::take_heap(bitmap)
233+
unsafe {
234+
let bitmap = ffi::roaring_bitmap_deserialize(buffer.as_ptr().cast::<c_void>());
235+
Bitmap::take_heap(bitmap)
236+
}
231237
}
232238
}
233239

@@ -261,9 +267,11 @@ impl ViewDeserializer for Frozen {
261267
///
262268
/// See [`BitmapView::deserialize`] for examples.
263269
unsafe fn deserialize_view(data: &[u8]) -> BitmapView<'_> {
264-
assert_eq!(data.as_ptr() as usize % Self::REQUIRED_ALIGNMENT, 0);
270+
unsafe {
271+
assert_eq!(data.as_ptr() as usize % Self::REQUIRED_ALIGNMENT, 0);
265272

266-
let roaring = ffi::roaring_bitmap_frozen_view(data.as_ptr().cast(), data.len());
267-
BitmapView::take_heap(roaring)
273+
let roaring = ffi::roaring_bitmap_frozen_view(data.as_ptr().cast(), data.len());
274+
BitmapView::take_heap(roaring)
275+
}
268276
}
269277
}

croaring/src/bitmap/view.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ impl<'a> BitmapView<'a> {
2121
#[inline]
2222
#[allow(clippy::assertions_on_constants)]
2323
pub(crate) unsafe fn take_heap(p: *const roaring_bitmap_t) -> Self {
24-
// This depends somewhat heavily on the implementation of croaring,
25-
// In particular, that `roaring_bitmap_t` doesn't store any pointers into itself
26-
// (it can be moved safely), and a "frozen" bitmap is stored in an arena, and the
27-
// `containers` array is stored immediately after the roaring_bitmap_t data.
28-
// Ensure this is still valid every time we update
29-
// the version of croaring.
30-
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4);
24+
unsafe {
25+
// This depends somewhat heavily on the implementation of croaring,
26+
// In particular, that `roaring_bitmap_t` doesn't store any pointers into itself
27+
// (it can be moved safely), and a "frozen" bitmap is stored in an arena, and the
28+
// `containers` array is stored immediately after the roaring_bitmap_t data.
29+
// Ensure this is still valid every time we update
30+
// the version of croaring.
31+
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4);
3132

32-
assert!(!p.is_null());
33+
assert!(!p.is_null());
3334

34-
// We will use this in the Drop implementation to re-create this pointer to pass to roaring_bitmap_free
35-
// If this fails, we would pass junk to roaring_bitmap_free in Drop.
36-
assert_eq!(p, original_bitmap_ptr(&*p));
35+
// We will use this in the Drop implementation to re-create this pointer to pass to roaring_bitmap_free
36+
// If this fails, we would pass junk to roaring_bitmap_free in Drop.
37+
assert_eq!(p, original_bitmap_ptr(&*p));
3738

38-
Self {
39-
bitmap: *p,
40-
phantom: PhantomData,
39+
Self {
40+
bitmap: *p,
41+
phantom: PhantomData,
42+
}
4143
}
4244
}
4345

@@ -60,7 +62,7 @@ impl<'a> BitmapView<'a> {
6062
/// The data must be the result of serializing a bitmap with the same serialization format
6163
#[must_use]
6264
pub unsafe fn deserialize<S: ViewDeserializer>(data: &'a [u8]) -> Self {
63-
S::deserialize_view(data)
65+
unsafe { S::deserialize_view(data) }
6466
}
6567

6668
/// Create an owned, mutable bitmap from this view

croaring/src/bitmap64/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a> Bitmap64Cursor<'a> {
129129
}
130130

131131
unsafe fn current_unchecked(&self) -> u64 {
132-
ffi::roaring64_iterator_value(self.raw.as_ptr())
132+
unsafe { ffi::roaring64_iterator_value(self.raw.as_ptr()) }
133133
}
134134

135135
/// Moves the cursor to the next value in the bitmap

croaring/src/bitmap64/serialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Deserializer for Portable {
159159
}
160160

161161
unsafe fn try_deserialize_unchecked(buffer: &[u8]) -> Bitmap64 {
162-
Self::try_deserialize(buffer).unwrap_unchecked()
162+
unsafe { Self::try_deserialize(buffer).unwrap_unchecked() }
163163
}
164164

165165
fn find_end(buffer: &[u8]) -> Option<NonZeroUsize> {

croaring/src/bitset/imp.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ impl Bitset {
55
#[inline]
66
#[allow(clippy::assertions_on_constants)]
77
pub(super) unsafe fn take_heap(p: *mut ffi::bitset_t) -> Self {
8-
assert!(!p.is_null());
9-
let result = Self { bitset: p.read() };
10-
// It seems unlikely that the bitset type will meaningfully change, but check if we ever go
11-
// to a version 3.
12-
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4);
13-
ffi::roaring_free(p.cast());
14-
result
8+
unsafe {
9+
assert!(!p.is_null());
10+
let result = Self { bitset: p.read() };
11+
// It seems unlikely that the bitset type will meaningfully change, but check if we ever go
12+
// to a version 3.
13+
const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4);
14+
ffi::roaring_free(p.cast());
15+
result
16+
}
1517
}
1618

1719
/// Access the raw underlying slice

0 commit comments

Comments
 (0)