Skip to content
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

Added array_permutations (attempt 2) #1014

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions src/combinations.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use core::array;
use std::fmt;
use std::iter::FusedIterator;

use super::lazy_buffer::{LazyBuffer, ArrayOrVecHelper};
use super::lazy_buffer::{ArrayOrVecHelper, ConstUsize, LazyBuffer, MaybeConstUsize as _};
use alloc::vec::Vec;

use crate::adaptors::checked_binomial;
use crate::lazy_buffer::MaybeConstUsize as _;

/// Iterator for `Vec` valued combinations returned by [`.combinations()`](crate::Itertools::combinations)
pub type Combinations<I> = CombinationsGeneric<I, Vec<usize>>;
Expand All @@ -18,15 +16,15 @@ pub fn combinations<I: Iterator>(iter: I, k: usize) -> Combinations<I>
where
I::Item: Clone,
{
Combinations::new(iter, (0..k).collect())
Combinations::new(iter, ArrayOrVecHelper::start(k))
}

/// Create a new `ArrayCombinations` from a clonable iterator.
pub fn array_combinations<I: Iterator, const K: usize>(iter: I) -> ArrayCombinations<I, K>
where
I::Item: Clone,
{
ArrayCombinations::new(iter, array::from_fn(|i| i))
ArrayCombinations::new(iter, ArrayOrVecHelper::start(ConstUsize))
ronnodas marked this conversation as resolved.
Show resolved Hide resolved
}

/// An iterator to iterate through all the `k`-length combinations in an iterator.
Expand Down