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

Commit

Permalink
also shrink the validity bitmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 30, 2021
1 parent a2bcd42 commit f70122b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ impl<O: Offset> MutableBinaryArray<O> {
/// Shrinks the capacity of the [`MutableBinaryArray`] to fit its current length.
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ impl MutableBooleanArray {
// Safety: `I` is `TrustedLen`
unsafe { Self::try_from_trusted_len_iter_unchecked(iterator) }
}

/// Shrinks the capacity of the [`MutableBooleanArray`] to fit its current length.
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

/// Creates a Bitmap and an optional [`MutableBitmap`] from an iterator of `Option<bool>`.
Expand Down Expand Up @@ -463,7 +471,7 @@ impl MutableArray for MutableBooleanArray {
}

fn shrink_to_fit(&mut self) {
// no-op still have to implement this for bitmaps
self.shrink_to_fit()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/array/dictionary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl<K: DictionaryKey, M: MutableArray> MutableDictionaryArray<K, M> {
/// Shrinks the capacity of the [`MutableDictionaryArray`] to fit its current length.
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
self.keys.shrink_to_fit();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ impl MutableFixedSizeBinaryArray {
/// Shrinks the capacity of the [`MutablePrimitive`] to fit its current length.
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/array/fixed_size_list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ impl<M: MutableArray> MutableFixedSizeListArray<M> {
}
/// Shrinks the capacity of the [`MutableFixedSizeList`] to fit its current length.
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit()
self.values.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ impl<O: Offset, M: MutableArray + Default> MutableListArray<O, M> {
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
self.offsets.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

Expand Down Expand Up @@ -185,7 +188,7 @@ impl<O: Offset, M: MutableArray> MutableListArray<O, M> {
}
}

impl<O: Offset, M: MutableArray + 'static> MutableArray for MutableListArray<O, M> {
impl<O: Offset, M: MutableArray + Default + 'static> MutableArray for MutableListArray<O, M> {
fn len(&self) -> usize {
self.offsets.len() - 1
}
Expand Down
3 changes: 3 additions & 0 deletions src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ impl<T: NativeType> MutablePrimitiveArray<T> {
/// Shrinks the capacity of the [`MutablePrimitive`] to fit its current length.
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ impl<O: Offset> MutableUtf8Array<O> {
pub fn shrink_to_fit(&mut self) {
self.values.shrink_to_fit();
self.offsets.shrink_to_fit();
if let Some(validity) = &mut self.validity {
validity.shrink_to_fit()
}
}
}

Expand Down

0 comments on commit f70122b

Please sign in to comment.