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

Added BooleanArray::from_trusted_len_values_iter_unchecked #799

Merged
merged 1 commit into from
Feb 3, 2022
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
13 changes: 13 additions & 0 deletions src/array/boolean/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ impl BooleanArray {
MutableBooleanArray::from_trusted_len_values_iter(iterator).into()
}

/// Creates a new [`BooleanArray`] from an [`TrustedLen`] of `bool`.
/// Use this over [`BooleanArray::from_trusted_len_iter`] when the iterator is trusted len
/// but this crate does not mark it as such.
/// # Safety
/// The iterator must be [`TrustedLen`](https://doc.rust-lang.org/std/iter/trait.TrustedLen.html).
/// I.e. that `size_hint().1` correctly reports its length.
#[inline]
pub unsafe fn from_trusted_len_values_iter_unchecked<I: Iterator<Item = bool>>(
iterator: I,
) -> Self {
MutableBooleanArray::from_trusted_len_values_iter_unchecked(iterator).into()
}

/// Creates a new [`BooleanArray`] from a slice of `bool`.
#[inline]
pub fn from_slice<P: AsRef<[bool]>>(slice: P) -> Self {
Expand Down
15 changes: 15 additions & 0 deletions src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ impl MutableBooleanArray {
)
}

/// Creates a new [`MutableBooleanArray`] from an [`TrustedLen`] of `bool`.
/// Use this over [`BooleanArray::from_trusted_len_iter`] when the iterator is trusted len
/// but this crate does not mark it as such.
/// # Safety
/// The iterator must be [`TrustedLen`](https://doc.rust-lang.org/std/iter/trait.TrustedLen.html).
/// I.e. that `size_hint().1` correctly reports its length.
#[inline]
pub unsafe fn from_trusted_len_values_iter_unchecked<I: Iterator<Item = bool>>(
iterator: I,
) -> Self {
let mut mutable = MutableBitmap::new();
mutable.extend_from_trusted_len_iter_unchecked(iterator);
MutableBooleanArray::from_data(DataType::Boolean, mutable, None)
}

/// Creates a new [`MutableBooleanArray`] from a slice of `bool`.
#[inline]
pub fn from_slice<P: AsRef<[bool]>>(slice: P) -> Self {
Expand Down