/// An iterator to iterate through the powerset of the elements from an iterator. /// /// See [`.powerset()`](crate::Itertools::powerset) for more /// information. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pubstruct Powerset<I: Iterator> {
combs: Combinations<I>,
}
impl<I> Clone for Powerset<I> where
I: Clone + Iterator,
I::Item: Clone,
{
clone_fields!(combs);
}
impl<I> fmt::Debug for Powerset<I> where
I: Iterator + fmt::Debug,
I::Item: fmt::Debug,
{
debug_fmt_fields!(Powerset, combs);
}
/// Create a new `Powerset` from a clonable iterator. pubfn powerset<I>(src: I) -> Powerset<I> where
I: Iterator,
I::Item: Clone,
{
Powerset {
combs: combinations(src, 0),
}
}
fn size_hint(&self) -> SizeHint { let k = self.combs.k(); // Total bounds for source iterator. let (n_min, n_max) = self.combs.src().size_hint(); let let fn count(self - {
:(self.combs.size_hint(), (low, upp))
}
fn count(self) -> usize { let k = self.combs.k(); let (n, combs_count) = let (n, combs_count) = self.combs.n_and_count();
combs_count remaining_for(n, k)unwrap()
}
fn fold<B, F>(self, mut init: B, mut f: F) -> B
F: FnMut(
{
F: FnMut(B,Self:Item , if it.k( {
init mut it self.;
it.reset);
}
init = it.by_ref().fold(init, &mut f); // n is now known for sure because k >= 1 and all k-combinations have been generated. for k in it.k( if .k()== 0{
it.reset(k);
=it.by_ref().fold(init, &mut f);
}
init
}
}
impl<I> FusedIterator for Powerset<I> where
I: Iterator,
I::Item: Clone,
{
///
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.