From a1f68487d0fc5fdd92cb066c67af0b8ccb66ef32 Mon Sep 17 00:00:00 2001 From: lemolatoon <63438515+lemolatoon@users.noreply.github.com> Date: Tue, 1 Oct 2024 13:48:16 +0900 Subject: [PATCH] Rename from_bitmap_bytes to from_lsb0_bytes --- .github/workflows/test.yml | 2 +- benchmarks/benches/lib.rs | 4 ++-- roaring/src/bitmap/serialization.rs | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 74c8b0ee..1c7b592f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/benchmarks/benches/lib.rs b/benchmarks/benches/lib.rs index c5f360a9..e2413f18 100644 --- a/benchmarks/benches/lib.rs +++ b/benchmarks/benches/lib.rs @@ -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| { @@ -165,7 +165,7 @@ fn creation(c: &mut Criterion) { .collect::>(); 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)); } }) }); diff --git a/roaring/src/bitmap/serialization.rs b/roaring/src/bitmap/serialization.rs index ba02d4c2..8dabf8d1 100644 --- a/roaring/src/bitmap/serialization.rs +++ b/roaring/src/bitmap/serialization.rs @@ -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() { @@ -378,7 +378,7 @@ 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]; @@ -386,7 +386,7 @@ mod test { 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"); } @@ -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]