Skip to content

Commit

Permalink
Minor: Improve comments on GenericByteViewArray::bytes_iter(), prefix…
Browse files Browse the repository at this point in the history
…_iter() and suffix_iter() (#6306)
  • Loading branch information
alamb authored Aug 28, 2024
1 parent b711f23 commit dc8427f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
ArrayIter::new(self)
}

/// Returns an iterator over the bytes of this array.
/// Returns an iterator over the bytes of this array, including null values
pub fn bytes_iter(&self) -> impl Iterator<Item = &[u8]> {
self.views.iter().map(move |v| {
let len = *v as u32;
Expand All @@ -317,8 +317,11 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
})
}

/// Returns an iterator over the prefix bytes of this array with respect to the prefix length.
/// If the prefix length is larger than the string length, it will return the empty slice.
/// Returns an iterator over the first `prefix_len` bytes of each array
/// element, including null values.
///
/// If `prefix_len` is larger than the element's length, the iterator will
/// return an empty slice (`&[]`).
pub fn prefix_bytes_iter(&self, prefix_len: usize) -> impl Iterator<Item = &[u8]> {
self.views().into_iter().map(move |v| {
let len = (*v as u32) as usize;
Expand All @@ -341,8 +344,14 @@ impl<T: ByteViewType + ?Sized> GenericByteViewArray<T> {
})
}

/// Returns an iterator over the suffix bytes of this array with respect to the suffix length.
/// If the suffix length is larger than the string length, it will return the empty slice.
/// Returns an iterator over the last `suffix_len` bytes of each array
/// element, including null values.
///
/// Note that for [`StringViewArray`] the last bytes may start in the middle
/// of a UTF-8 codepoint, and thus may not be a valid `&str`.
///
/// If `suffix_len` is larger than the element's length, the iterator will
/// return an empty slice (`&[]`).
pub fn suffix_bytes_iter(&self, suffix_len: usize) -> impl Iterator<Item = &[u8]> {
self.views().into_iter().map(move |v| {
let len = (*v as u32) as usize;
Expand Down

0 comments on commit dc8427f

Please sign in to comment.