alamb commented on code in PR #10759:
URL: https://github.com/apache/arrow-rs/pull/10759#discussion_r3880094979
##########
arrow-buffer/src/buffer/offset.rs:
##########
@@ -177,6 +177,42 @@ impl<O: ArrowNativeType> OffsetBuffer<O> {
Self(ScalarBuffer::from(offsets))
}
+ /// The first offset, i.e. the start of the first range.
+ ///
+ /// An [`OffsetBuffer`] is never empty, so this always returns an offset.
+ ///
+ /// ```
+ /// # use arrow_buffer::OffsetBuffer;
+ /// let offsets = OffsetBuffer::<i32>::from_lengths([1, 3, 5]);
+ /// assert_eq!(offsets.first(), 0);
+ /// assert_eq!(OffsetBuffer::<i32>::new_empty().first(), 0);
+ /// ```
+ #[inline]
+ pub fn first(&self) -> O {
+ self.0
+ .first()
+ .copied()
+ .expect("An `OffsetBuffer` is never empty")
+ }
+
+ /// The last offset, i.e. the end of the last range.
+ ///
+ /// An [`OffsetBuffer`] is never empty, so this always returns an offset.
+ ///
+ /// ```
+ /// # use arrow_buffer::OffsetBuffer;
+ /// let offsets = OffsetBuffer::<i32>::from_lengths([1, 3, 5]);
+ /// assert_eq!(offsets.last(), 9);
+ /// assert_eq!(OffsetBuffer::<i32>::new_empty().last(), 0);
+ /// ```
+ #[inline]
+ pub fn last(&self) -> O {
Review Comment:
I wonder if this would be confusing to people / get confused with
std::iterator::last 🤔
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.last
However, since the OffsetBuffer isn't an interator, this seems good to me
##########
arrow-buffer/src/buffer/offset.rs:
##########
@@ -177,6 +177,42 @@ impl<O: ArrowNativeType> OffsetBuffer<O> {
Self(ScalarBuffer::from(offsets))
}
+ /// The first offset, i.e. the start of the first range.
+ ///
+ /// An [`OffsetBuffer`] is never empty, so this always returns an offset.
+ ///
+ /// ```
+ /// # use arrow_buffer::OffsetBuffer;
+ /// let offsets = OffsetBuffer::<i32>::from_lengths([1, 3, 5]);
+ /// assert_eq!(offsets.first(), 0);
+ /// assert_eq!(OffsetBuffer::<i32>::new_empty().first(), 0);
+ /// ```
+ #[inline]
+ pub fn first(&self) -> O {
+ self.0
+ .first()
+ .copied()
+ .expect("An `OffsetBuffer` is never empty")
+ }
Review Comment:
I am not sure why it would cause churn downstream 🤔 `first_offset` is more
explicit and maybe less likely to be confused with an iterator name
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]