Skip to content

Commit

Permalink
Apply cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lemolatoon committed Dec 3, 2024
1 parent 2f8d368 commit 1b42145
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
7 changes: 2 additions & 5 deletions roaring/src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ impl Container {
pub fn full(key: u16) -> Container {
Container { key, store: Store::full() }
}

pub fn from_lsb0_bytes(key: u16, bytes: &[u8], byte_offset: usize) -> Option<Self> {
Some(Container {
key,
store: Store::from_lsb0_bytes(bytes, byte_offset)?,
})
Some(Container { key, store: Store::from_lsb0_bytes(bytes, byte_offset)? })
}
}

Expand Down
13 changes: 6 additions & 7 deletions roaring/src/bitmap/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::RoaringBitmap;
use bytemuck::cast_slice_mut;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use core::convert::Infallible;
use core::ops::RangeInclusive;
use core::mem::size_of;
use core::ops::RangeInclusive;
use std::error::Error;
use std::io;

Expand Down Expand Up @@ -132,7 +132,7 @@ impl RoaringBitmap {

start_container += 1;
}

// Handle all full containers
for full_container_key in start_container..end_container_inc {
let (src, rest) = bytes.split_at(BITMAP_LENGTH * size_of::<u64>());
Expand Down Expand Up @@ -411,28 +411,27 @@ mod test {

let rb = RoaringBitmap::from_bitmap_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);
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);
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() {
let bytes = [0x01];
RoaringBitmap::from_bitmap_bytes(1, &bytes);
}

#[test]
#[should_panic(expected = "<= 2^32")]
fn test_from_bitmap_bytes_overflow() {
Expand Down
6 changes: 3 additions & 3 deletions roaring/src/bitmap/store/array_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::bitmap::store::array_store::visitor::{CardinalityCounter, VecWriter};
use core::cmp::Ordering;
use core::cmp::Ordering::*;
use core::fmt::{Display, Formatter};
use core::ops::{BitAnd, BitAndAssign, BitOr, BitXor, RangeInclusive, Sub, SubAssign};
use core::mem::size_of;
use core::ops::{BitAnd, BitAndAssign, BitOr, BitXor, RangeInclusive, Sub, SubAssign};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
Expand Down Expand Up @@ -55,7 +55,7 @@ impl ArrayStore {

pub fn from_lsb0_bytes(bytes: &[u8], byte_offset: usize, bits_set: u64) -> Self {
type Word = u64;

let mut vec = Vec::with_capacity(bits_set as usize);

let chunks = bytes.chunks_exact(size_of::<Word>());
Expand All @@ -76,7 +76,7 @@ impl ArrayStore {
byte &= byte - 1;
}
}

Self::from_vec_unchecked(vec)
}

Expand Down

0 comments on commit 1b42145

Please sign in to comment.