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

Commit

Permalink
BooleanArray::into_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 3, 2022
1 parent 777f375 commit 5fdda18
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
bitmap::Bitmap,
datatypes::{DataType, PhysicalType},
};
use either::Either;

use super::{display_fmt, Array};

Expand Down Expand Up @@ -95,6 +96,42 @@ impl BooleanArray {
arr.validity = validity;
arr
}

/// Try to convert this `BooleanArray` to a `MutableBooleanArray`
pub fn into_mut(self) -> Either<Self, MutableBooleanArray> {
use Either::*;

if let Some(bitmap) = self.validity {
match bitmap.into_mut() {
Left(bitmap) => Left(BooleanArray::from_data(
self.data_type,
self.values,
Some(bitmap),
)),
Right(mutable_bitmap) => match self.values.into_mut() {
Left(immutable) => Left(BooleanArray::from_data(
self.data_type,
immutable,
Some(mutable_bitmap.into()),
)),
Right(mutable) => Right(MutableBooleanArray::from_data(
self.data_type,
mutable,
Some(mutable_bitmap),
)),
},
}
} else {
match self.values.into_mut() {
Left(immutable) => Left(BooleanArray::from_data(self.data_type, immutable, None)),
Right(mutable) => Right(MutableBooleanArray::from_data(
self.data_type,
mutable,
None,
)),
}
}
}
}

// accessors
Expand Down

0 comments on commit 5fdda18

Please sign in to comment.