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

Improved API docs for PrimitiveArray and Utf8Array #1017

Merged
merged 2 commits into from
May 28, 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
2 changes: 1 addition & 1 deletion src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<O: Offset> BinaryArray<O> {
Self::try_new_unchecked(data_type, offsets, values, validity).unwrap()
}

/// Alias for [`new_unchecked`]
/// Alias for [`Self::new_unchecked`]
/// # Safety
/// This function is unsafe iff:
/// * the offsets are not monotonically increasing
Expand Down
2 changes: 1 addition & 1 deletion src/array/equal/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::array::{Array, Offset, Utf8Array};
use crate::array::{Offset, Utf8Array};

pub(super) fn equal<O: Offset>(lhs: &Utf8Array<O>, rhs: &Utf8Array<O>) -> bool {
lhs.data_type() == rhs.data_type() && lhs.len() == rhs.len() && lhs.iter().eq(rhs.iter())
Expand Down
2 changes: 1 addition & 1 deletion src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl FixedSizeBinaryArray {
.get_unchecked(i * self.size..(i + 1) * self.size)
}

/// Returns a new [`FixedSizeBinary`] with a different logical type.
/// Returns a new [`FixedSizeBinaryArray`] with a different logical type.
/// This is `O(1)`.
/// # Panics
/// Panics iff the data_type is not supported for the physical type.
Expand Down
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