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

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed May 28, 2022
1 parent b8c151d commit f441847
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 170 deletions.
58 changes: 1 addition & 57 deletions src/array/primitive/from_natural.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::iter::FromIterator;

use crate::{trusted_len::TrustedLen, types::NativeType};
use crate::types::NativeType;

use super::{MutablePrimitiveArray, PrimitiveArray};

Expand All @@ -15,59 +15,3 @@ impl<T: NativeType, Ptr: std::borrow::Borrow<Option<T>>> FromIterator<Ptr> for P
MutablePrimitiveArray::<T>::from_iter(iter).into()
}
}

impl<T: NativeType> PrimitiveArray<T> {
/// Creates a (non-null) [`PrimitiveArray`] from an iterator of values.
/// # Implementation
/// This does not assume that the iterator has a known length.
pub fn from_values<I: IntoIterator<Item = T>>(iter: I) -> Self {
Self::new(T::PRIMITIVE.into(), Vec::<T>::from_iter(iter).into(), None)
}

/// Creates a (non-null) [`PrimitiveArray`] from a slice of values.
/// # Implementation
/// This is essentially a memcopy
pub fn from_slice<P: AsRef<[T]>>(slice: P) -> Self {
Self::new(
T::PRIMITIVE.into(),
Vec::<T>::from(slice.as_ref()).into(),
None,
)
}

/// Creates a (non-null) [`PrimitiveArray`] from a vector of values.
/// This does not have memcopy and is the fastest way to create a [`PrimitiveArray`].
pub fn from_vec(array: Vec<T>) -> Self {
Self::new(T::PRIMITIVE.into(), array.into(), None)
}
}

impl<T: NativeType> PrimitiveArray<T> {
/// Creates a (non-null) [`PrimitiveArray`] from a [`TrustedLen`] of values.
/// # Implementation
/// This does not assume that the iterator has a known length.
pub fn from_trusted_len_values_iter<I: TrustedLen<Item = T>>(iter: I) -> Self {
MutablePrimitiveArray::<T>::from_trusted_len_values_iter(iter).into()
}

/// Creates a new [`PrimitiveArray`] from an iterator over values
/// # 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.
pub unsafe fn from_trusted_len_values_iter_unchecked<I: Iterator<Item = T>>(iter: I) -> Self {
MutablePrimitiveArray::<T>::from_trusted_len_values_iter_unchecked(iter).into()
}

/// Creates a [`PrimitiveArray`] from a [`TrustedLen`] of optional values.
pub fn from_trusted_len_iter<I: TrustedLen<Item = Option<T>>>(iter: I) -> Self {
MutablePrimitiveArray::<T>::from_trusted_len_iter(iter).into()
}

/// Creates a [`PrimitiveArray`] from an iterator of optional values.
/// # 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.
pub unsafe fn from_trusted_len_iter_unchecked<I: Iterator<Item = Option<T>>>(iter: I) -> Self {
MutablePrimitiveArray::<T>::from_trusted_len_iter_unchecked(iter).into()
}
}
11 changes: 0 additions & 11 deletions src/array/primitive/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ impl<'a, T: NativeType> IntoIterator for &'a PrimitiveArray<T> {
}
}

impl<'a, T: NativeType> PrimitiveArray<T> {
/// constructs a new iterator
#[inline]
pub fn iter(&'a self) -> ZipValidity<'a, &'a T, std::slice::Iter<'a, T>> {
zip_validity(
self.values().iter(),
self.validity.as_ref().map(|x| x.iter()),
)
}
}

impl<'a, T: NativeType> MutablePrimitiveArray<T> {
/// Returns an iterator over `Option<T>`
#[inline]
Expand Down
Loading

0 comments on commit f441847

Please sign in to comment.