Skip to content

Lazybuffer::it private #732

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

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/combinations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt;
use std::iter::{Fuse, FusedIterator};
use std::iter::FusedIterator;

use super::lazy_buffer::LazyBuffer;
use alloc::vec::Vec;
Expand Down Expand Up @@ -52,9 +52,9 @@ impl<I: Iterator> Combinations<I> {
#[inline]
pub fn n(&self) -> usize { self.pool.len() }

/// Returns a reference to the source iterator.
/// Returns a reference to the source pool.
#[inline]
pub(crate) fn src(&self) -> &Fuse<I> { &self.pool.it }
pub(crate) fn src(&self) -> &LazyBuffer<I> { &self.pool }

/// Resets this `Combinations` back to an initial state for combinations of length
/// `k` over the same pool data source. If `k` is larger than the current length
Expand Down Expand Up @@ -130,8 +130,7 @@ impl<I> Iterator for Combinations<I>

fn count(self) -> usize {
let Self { indices, pool, first } = self;
// TODO: make `pool.it` private
let n = pool.len() + pool.it.count();
let n = pool.count();
remaining_for(n, first, &indices).unwrap()
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/lazy_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::size_hint::{self, SizeHint};

#[derive(Debug, Clone)]
pub struct LazyBuffer<I: Iterator> {
pub it: Fuse<I>,
it: Fuse<I>,
buffer: Vec<I::Item>,
}

Expand All @@ -29,6 +29,10 @@ where
size_hint::add_scalar(self.it.size_hint(), self.len())
}

pub fn count(self) -> usize {
self.len() + self.it.count()
}

pub fn get_next(&mut self) -> bool {
if let Some(x) = self.it.next() {
self.buffer.push(x);
Expand Down
4 changes: 2 additions & 2 deletions src/permutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ where
let Permutations { vals, state } = self;
match state {
PermutationState::StartUnknownLen { k } => {
let n = vals.len() + vals.it.count();
let n = vals.count();
let complete_state = CompleteState::Start { n, k };

from_complete(complete_state)
}
PermutationState::OngoingUnknownLen { k, min_n } => {
let prev_iteration_count = min_n - k + 1;
let n = vals.len() + vals.it.count();
let n = vals.count();
let complete_state = CompleteState::Start { n, k };

from_complete(complete_state) - prev_iteration_count
Expand Down
2 changes: 1 addition & 1 deletion src/powerset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<I> Iterator for Powerset<I>

fn size_hint(&self) -> (usize, Option<usize>) {
// Total bounds for source iterator.
let src_total = size_hint::add_scalar(self.combs.src().size_hint(), self.combs.n());
let src_total = self.combs.src().size_hint();

// Total bounds for self ( length(powerset(set) == 2 ^ length(set) )
let self_total = size_hint::pow_scalar_base(2, src_total);
Expand Down