Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency between code and comment #872

Open
YichiZhang0613 opened this issue Nov 25, 2024 · 0 comments
Open

Inconsistency between code and comment #872

YichiZhang0613 opened this issue Nov 25, 2024 · 0 comments

Comments

@YichiZhang0613
Copy link

In geoarrow-rs/rust/geoarrow/src/array/mixed/array.rs, the comment indicate the code panics if offset + length >= self.len() while the code will panic if offset + length < self.len()

/// # Panic
///
/// This function panics iff `offset + length >= self.len()`.
#[inline]
pub fn slice(&self, offset: usize, length: usize) -> Self {
    assert!(
        offset + length <= self.len(),
        "offset + length may not exceed length of array"
    );

In geoarrow-rs/rust/geoarrow/src/array/util.rs, the comment indicate the code panics if index >= self.len() while the code will panic if index >= self.len() -1

impl<O: OffsetSizeTrait> OffsetBufferUtils<O> for OffsetBuffer<O> {
    /// Returns the length an array with these offsets would be.
    #[inline]
    fn len_proxy(&self) -> usize {
        self.len() - 1
    }

    /// Returns a range (start, end) corresponding to the position `index`
    ///
    /// # Panic
    ///
    /// Panics iff `index >= self.len()`
    #[inline]
    fn start_end(&self, index: usize) -> (usize, usize) {
        assert!(index < self.len_proxy());
        let start = self[index].to_usize().unwrap();
        let end = self[index + 1].to_usize().unwrap();
        (start, end)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant