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

Added MutableBitmap::shrink_to_fit #468

Merged
merged 1 commit into from
Sep 29, 2021
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
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);
}