Skip to content

Commit

Permalink
ARROW-11313: [Rust] Fixed size_hint
Browse files Browse the repository at this point in the history
`size_hint` should return the remaining items, not the total number of items.

Closes apache#9258 from jorgecarleitao/fix_size_hint

Authored-by: Jorge C. Leitao <jorgecarleitao@gmail.com>
Signed-off-by: Andrew Lamb <andrew@nerdnetworks.org>
  • Loading branch information
jorgecarleitao authored and michalursa committed Jun 13, 2021
1 parent 65d10dd commit ceb4622
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rust/arrow/src/array/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ impl<'a, T: ArrowPrimitiveType> std::iter::Iterator for PrimitiveIter<'a, T> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.array.len(), Some(self.array.len()))
(
self.array.len() - self.current,
Some(self.array.len() - self.current),
)
}
}

Expand Down Expand Up @@ -118,7 +121,10 @@ impl<'a> std::iter::Iterator for BooleanIter<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.array.len(), Some(self.array.len()))
(
self.array.len() - self.current,
Some(self.array.len() - self.current),
)
}
}

Expand Down Expand Up @@ -179,7 +185,7 @@ impl<'a, T: StringOffsetSizeTrait> std::iter::Iterator for GenericStringIter<'a,
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
(self.len - self.i, Some(self.len - self.i))
}
}

Expand Down Expand Up @@ -228,7 +234,7 @@ impl<'a, T: BinaryOffsetSizeTrait> std::iter::Iterator for GenericBinaryIter<'a,
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.len, Some(self.len))
(self.len - self.i, Some(self.len - self.i))
}
}

Expand Down

0 comments on commit ceb4622

Please sign in to comment.