Skip to content

Commit

Permalink
Use ArrayOrVecHelper::start in {Array,}Combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnodas committed Jan 13, 2025
1 parent d8de4b8 commit 57fff6e
Showing 1 changed file with 3 additions and 5 deletions.
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))
}

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

0 comments on commit 57fff6e

Please # to comment.