diff --git a/src/setu64/iter.rs b/src/setu64/iter.rs index 6a8dfb9..1b9a4d6 100644 --- a/src/setu64/iter.rs +++ b/src/setu64/iter.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use super::{mask, unsplit_u64, Internal, SetU64}; impl SetU64 { @@ -21,6 +23,7 @@ impl SetU64 { sz_left: s.sz, bits: s.bits, a, + start_at: 0, }), Internal::Dense { a, sz } => Iter::Dense(DenseIter { sz_left: sz, @@ -37,7 +40,7 @@ enum Iter<'a> { Empty, Stack(super::Tiny), Heap(HeapIter<'a>), - Big(BigIter<'a>), + Big(BigIter<&'a [u64]>), Dense(DenseIter<'a>), } @@ -96,18 +99,19 @@ impl<'a> Iterator for Iter<'a> { } #[derive(Debug, Clone)] -struct BigIter<'a> { +struct BigIter { sz_left: usize, bits: u64, - a: &'a [u64], + a: V, + start_at: usize, } -impl<'a> Iterator for BigIter<'a> { +impl> Iterator for BigIter { type Item = u64; #[inline] fn next(&mut self) -> Option { - while let Some((&x, rest)) = self.a.split_first() { - self.a = rest; + while let Some(&x) = self.a.get(self.start_at) { + self.start_at += 1; if x != 0 { self.sz_left -= 1; return Some(if x == self.bits { 0 } else { x });