Skip to content
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
10 changes: 5 additions & 5 deletions roaring/src/bitmap/ops_with_serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ impl RoaringBitmap {
let size = ((cookie >> 16) + 1) as usize;
(size, size >= NO_OFFSET_THRESHOLD, true)
} else {
return Err(io::Error::new(io::ErrorKind::Other, "unknown cookie value"));
return Err(io::Error::other("unknown cookie value"));
}
};

// Read the run container bitmap if necessary
let run_container_bitmap = if has_run_containers {
let mut bitmap = vec![0u8; (size + 7) / 8];
let mut bitmap = vec![0u8; size.div_ceil(8)];
reader.read_exact(&mut bitmap)?;
Some(bitmap)
} else {
None
};

if size > u16::MAX as usize + 1 {
return Err(io::Error::new(io::ErrorKind::Other, "size is greater than supported"));
return Err(io::Error::other("size is greater than supported"));
}

// Read the container descriptions
Expand Down Expand Up @@ -125,7 +125,7 @@ impl RoaringBitmap {

// If the run container bitmap is present, check if this container is a run container
let is_run_container =
run_container_bitmap.as_ref().map_or(false, |bm| bm[i / 8] & (1 << (i % 8)) != 0);
run_container_bitmap.as_ref().is_some_and(|bm| bm[i / 8] & (1 << (i % 8)) != 0);

let store = if is_run_container {
let runs = reader.read_u16::<LittleEndian>()?;
Expand Down Expand Up @@ -232,7 +232,7 @@ impl RoaringBitmap {

// If the run container bitmap is present, check if this container is a run container
let is_run_container =
run_container_bitmap.as_ref().map_or(false, |bm| bm[i / 8] & (1 << (i % 8)) != 0);
run_container_bitmap.as_ref().is_some_and(|bm| bm[i / 8] & (1 << (i % 8)) != 0);

let store = if is_run_container {
let runs = reader.read_u16::<LittleEndian>().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions roaring/src/bitmap/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl RoaringBitmap {
let cookie = SERIAL_COOKIE as u32 | ((size as u32 - 1) << 16);
writer.write_u32::<LittleEndian>(cookie)?;
// It is then followed by a bitset indicating which containers are run containers
let run_container_bitmap_size = (size + 7) / 8;
let run_container_bitmap_size = size.div_ceil(8);
let mut run_container_bitmap = vec![0; run_container_bitmap_size];
for (i, container) in self.containers.iter().enumerate() {
if let Store::Run(_) = container.store {
Expand Down Expand Up @@ -223,21 +223,21 @@ impl RoaringBitmap {
let size = ((cookie >> 16) + 1) as usize;
(size, size >= NO_OFFSET_THRESHOLD, true)
} else {
return Err(io::Error::new(io::ErrorKind::Other, "unknown cookie value"));
return Err(io::Error::other("unknown cookie value"));
}
};

// Read the run container bitmap if necessary
let run_container_bitmap = if has_run_containers {
let mut bitmap = vec![0u8; (size + 7) / 8];
let mut bitmap = vec![0u8; size.div_ceil(8)];
reader.read_exact(&mut bitmap)?;
Some(bitmap)
} else {
None
};

if size > u16::MAX as usize + 1 {
return Err(io::Error::new(io::ErrorKind::Other, "size is greater than supported"));
return Err(io::Error::other("size is greater than supported"));
}

// Read the container descriptions
Expand Down Expand Up @@ -269,7 +269,7 @@ impl RoaringBitmap {

// If the run container bitmap is present, check if this container is a run container
let is_run_container =
run_container_bitmap.as_ref().map_or(false, |bm| bm[i / 8] & (1 << (i % 8)) != 0);
run_container_bitmap.as_ref().is_some_and(|bm| bm[i / 8] & (1 << (i % 8)) != 0);

let store = if is_run_container {
let runs = reader.read_u16::<LittleEndian>()?;
Expand Down Expand Up @@ -329,7 +329,7 @@ fn header_size(size: usize, has_run_containers: bool) -> usize {
if has_run_containers {
// New format encodes the size (number of containers) into the 4 byte cookie
// Additionally a bitmap is included marking which containers are run containers
let run_container_bitmap_size = (size + 7) / 8;
let run_container_bitmap_size = size.div_ceil(8);
// New format conditionally includes offsets if there are 4 or more containers
if size >= NO_OFFSET_THRESHOLD {
COOKIE_BYTES + ((DESCRIPTION_BYTES + OFFSET_BYTES) * size) + run_container_bitmap_size
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/store/array_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl BitAndAssign<&Self> for ArrayStore {
let mut i = 0;
self.retain(|x| {
i += rhs.iter().skip(i).position(|y| *y >= x).unwrap_or(rhs.vec.len());
rhs.vec.get(i).map_or(false, |y| x == *y)
rhs.vec.get(i).is_some_and(|y| x == *y)
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl BitmapStore {

pub fn from_lsb0_bytes_unchecked(bytes: &[u8], byte_offset: usize, bits_set: u64) -> Self {
const BITMAP_BYTES: usize = BITMAP_LENGTH * size_of::<u64>();
assert!(byte_offset.checked_add(bytes.len()).map_or(false, |sum| sum <= BITMAP_BYTES));
assert!(byte_offset.checked_add(bytes.len()).is_some_and(|sum| sum <= BITMAP_BYTES));

// If we know we're writing the full bitmap, we can avoid the initial memset to 0
let mut bits = if bytes.len() == BITMAP_BYTES {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl BitmapStore {
if !cfg!(target_endian = "little") {
// Convert all words we touched (even partially) to little-endian
let start_word = byte_offset / size_of::<u64>();
let end_word = (byte_offset + bytes.len() + (size_of::<u64>() - 1)) / size_of::<u64>();
let end_word = (byte_offset + bytes.len()).div_ceil(size_of::<u64>());

// The 0th byte is the least significant byte, so we've written the bytes in little-endian
for word in &mut bits[start_word..end_word] {
Expand Down
Loading