Skip to content

Commit

Permalink
change BigIter to be generic over storage
Browse files Browse the repository at this point in the history
  • Loading branch information
droundy committed Sep 7, 2024
1 parent 1336e6a commit 5ad595c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/setu64/iter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use super::{mask, unsplit_u64, Internal, SetU64};

impl SetU64 {
Expand All @@ -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,
Expand All @@ -37,7 +40,7 @@ enum Iter<'a> {
Empty,
Stack(super::Tiny),
Heap(HeapIter<'a>),
Big(BigIter<'a>),
Big(BigIter<&'a [u64]>),
Dense(DenseIter<'a>),
}

Expand Down Expand Up @@ -96,18 +99,19 @@ impl<'a> Iterator for Iter<'a> {
}

#[derive(Debug, Clone)]
struct BigIter<'a> {
struct BigIter<V> {
sz_left: usize,
bits: u64,
a: &'a [u64],
a: V,
start_at: usize,
}

impl<'a> Iterator for BigIter<'a> {
impl<V: Deref<Target = [u64]>> Iterator for BigIter<V> {
type Item = u64;
#[inline]
fn next(&mut self) -> Option<u64> {
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 });
Expand Down

0 comments on commit 5ad595c

Please sign in to comment.