Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
undo changes and fix root cause
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 16, 2022
1 parent 0640015 commit 14297d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,12 @@ impl Bitmap {
pub fn make_mut(self) -> MutableBitmap {
match self.into_mut() {
Either::Left(data) => {
MutableBitmap::from_vec(data.bytes.as_ref().to_vec(), data.length)
if data.offset > 0 {
// we have to recreate the bytes because a MutableBitmap does not have an `offset`.
data.iter().collect()
} else {
MutableBitmap::from_vec(data.bytes.as_ref().to_vec(), data.length)
}
}
Either::Right(data) => data,
}
Expand Down
2 changes: 1 addition & 1 deletion src/bitmap/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl MutableBitmap {

/// Returns an iterator over mutable slices, [`BitChunksExactMut`]
pub(crate) fn bitchunks_exact_mut<T: BitChunk>(&mut self) -> BitChunksExactMut<T> {
BitChunksExactMut::new(&mut self.buffer)
BitChunksExactMut::new(&mut self.buffer, self.length)
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/bitmap/utils/chunks_exact_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ pub struct BitChunksExactMut<'a, T: BitChunk> {
impl<'a, T: BitChunk> BitChunksExactMut<'a, T> {
/// Returns a new [`BitChunksExactMut`]
#[inline]
pub fn new(bitmap: &'a mut [u8]) -> Self {
pub fn new(bitmap: &'a mut [u8], length: usize) -> Self {
let size_of = std::mem::size_of::<T>();

let length = bitmap.len();
let split = (length / size_of) * size_of;
let split = (length / 8 / size_of) * size_of;
let (chunks, remainder) = bitmap.split_at_mut(split);
let remainder_len = (length - chunks.len()) * 8;
let remainder_len = length - chunks.len() * 8;

let chunks = chunks.chunks_exact_mut(size_of);
Self {
Expand Down

0 comments on commit 14297d3

Please sign in to comment.