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

Commit

Permalink
Added MutableBitmap::shrink_to_fit (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Sep 29, 2021
1 parent 10acbcc commit 2db7f57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/bitmap/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ impl MutableBitmap {
pub fn set(&mut self, index: usize, value: bool) {
set_bit(&mut self.buffer.as_mut_slice(), index, value)
}

/// Shrinks the capacity of the [`MutableBitmap`] to fit its current length.
/// When the feature `cache_aligned`, the new capacity will be a multiple of 64 bytes.
pub fn shrink_to_fit(&mut self) {
self.buffer.shrink_to_fit();
}
}

impl MutableBitmap {
Expand Down
8 changes: 8 additions & 0 deletions tests/it/bitmap/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,11 @@ fn extend_bitmap_other() {
])
);
}

#[test]
fn shrink_to_fit() {
let mut a = MutableBitmap::with_capacity(1025);
a.push(false);
a.shrink_to_fit();
assert!(a.capacity() < 1025);
}

0 comments on commit 2db7f57

Please sign in to comment.