Skip to content

Commit

Permalink
Rename from_bitmap_bytes to from_lsb0_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon committed Oct 31, 2024
1 parent f0dbb72 commit 915e582
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: miri
args: test --target s390x-unknown-linux-gnu --package roaring --lib -- bitmap::serialization::test::test_from_bitmap_bytes
args: test --target s390x-unknown-linux-gnu --package roaring --lib -- bitmap::serialization::test::test_from_lsb0_bytes

- name: Test no default features
uses: actions-rs/cargo@v1
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn creation(c: &mut Criterion) {

group.throughput(Throughput::Elements(dataset.bitmaps.iter().map(|rb| rb.len()).sum()));

group.bench_function(BenchmarkId::new("from_bitmap_bytes", &dataset.name), |b| {
group.bench_function(BenchmarkId::new("from_lsb0_bytes", &dataset.name), |b| {
let bitmap_bytes = dataset_numbers
.iter()
.map(|bitmap_numbers| {
Expand All @@ -165,7 +165,7 @@ fn creation(c: &mut Criterion) {
.collect::<Vec<_>>();
b.iter(|| {
for bitmap_bytes in &bitmap_bytes {
black_box(RoaringBitmap::from_bitmap_bytes(0, bitmap_bytes));
black_box(RoaringBitmap::from_lsb0_bytes(0, bitmap_bytes));
}
})
});
Expand Down
26 changes: 13 additions & 13 deletions roaring/src/bitmap/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ impl RoaringBitmap {
/// let bytes = [0b00000101, 0b00000010, 0b00000000, 0b10000000];
/// // ^^^^^^^^ ^^^^^^^^ ^^^^^^^^ ^^^^^^^^
/// // 76543210 98
/// let rb = RoaringBitmap::from_bitmap_bytes(0, &bytes);
/// let rb = RoaringBitmap::from_lsb0_bytes(0, &bytes);
/// assert!(rb.contains(0));
/// assert!(!rb.contains(1));
/// assert!(rb.contains(2));
/// assert!(rb.contains(9));
/// assert!(rb.contains(31));
///
/// let rb = RoaringBitmap::from_bitmap_bytes(8, &bytes);
/// let rb = RoaringBitmap::from_lsb0_bytes(8, &bytes);
/// assert!(rb.contains(8));
/// assert!(!rb.contains(9));
/// assert!(rb.contains(10));
/// assert!(rb.contains(17));
/// assert!(rb.contains(39));
/// ```
pub fn from_bitmap_bytes(offset: u32, mut bytes: &[u8]) -> RoaringBitmap {
pub fn from_lsb0_bytes(offset: u32, mut bytes: &[u8]) -> RoaringBitmap {
assert_eq!(offset % 8, 0, "offset must be a multiple of 8");

if bytes.is_empty() {
Expand Down Expand Up @@ -378,15 +378,15 @@ mod test {
}

#[test]
fn test_from_bitmap_bytes() {
fn test_from_lsb0_bytes() {
const CONTAINER_OFFSET: u32 = u64::BITS * BITMAP_LENGTH as u32;
const CONTAINER_OFFSET_IN_BYTES: u32 = CONTAINER_OFFSET / 8;
let mut bytes = vec![0xff; CONTAINER_OFFSET_IN_BYTES as usize];
bytes.extend(&[0x00; CONTAINER_OFFSET_IN_BYTES as usize]);
bytes.extend(&[0b00000001, 0b00000010, 0b00000011, 0b00000100]);

let offset = 32;
let rb = RoaringBitmap::from_bitmap_bytes(offset, &bytes);
let rb = RoaringBitmap::from_lsb0_bytes(offset, &bytes);
for i in 0..offset {
assert!(!rb.contains(i), "{i} should not be in the bitmap");
}
Expand All @@ -406,37 +406,37 @@ mod test {
// Ensure the empty container is not created
let mut bytes = vec![0x00u8; CONTAINER_OFFSET_IN_BYTES as usize];
bytes.extend(&[0xff]);
let rb = RoaringBitmap::from_bitmap_bytes(0, &bytes);
let rb = RoaringBitmap::from_lsb0_bytes(0, &bytes);
assert_eq!(rb.min(), Some(CONTAINER_OFFSET));

let rb = RoaringBitmap::from_bitmap_bytes(8, &bytes);
let rb = RoaringBitmap::from_lsb0_bytes(8, &bytes);
assert_eq!(rb.min(), Some(CONTAINER_OFFSET + 8));

// Ensure we can set the last byte in an array container
let bytes = [0x80];
let rb = RoaringBitmap::from_bitmap_bytes(0xFFFFFFF8, &bytes);
let rb = RoaringBitmap::from_lsb0_bytes(0xFFFFFFF8, &bytes);
assert_eq!(rb.len(), 1);
assert!(rb.contains(u32::MAX));

// Ensure we can set the last byte in a bitmap container
let bytes = vec![0xFF; 0x1_0000 / 8];
let rb = RoaringBitmap::from_bitmap_bytes(0xFFFF0000, &bytes);
let rb = RoaringBitmap::from_lsb0_bytes(0xFFFF0000, &bytes);
assert_eq!(rb.len(), 0x1_0000);
assert!(rb.contains(u32::MAX));
}

#[test]
#[should_panic(expected = "multiple of 8")]
fn test_from_bitmap_bytes_invalid_offset() {
fn test_from_lsb0_bytes_invalid_offset() {
let bytes = [0x01];
RoaringBitmap::from_bitmap_bytes(1, &bytes);
RoaringBitmap::from_lsb0_bytes(1, &bytes);
}

#[test]
#[should_panic(expected = "<= 2^32")]
fn test_from_bitmap_bytes_overflow() {
fn test_from_lsb0_bytes_overflow() {
let bytes = [0x01, 0x01];
RoaringBitmap::from_bitmap_bytes(u32::MAX - 7, &bytes);
RoaringBitmap::from_lsb0_bytes(u32::MAX - 7, &bytes);
}

#[test]
Expand Down

0 comments on commit 915e582

Please sign in to comment.