pub struct BinomialIter { /* private fields */ }
Expand description
Provides methods to calculate the binomial coefficient for the next
higher/lower n
/k
.
Implementations§
Source§impl BinomialIter
impl BinomialIter
Sourcepub fn new(n: u32, k: u32) -> BinomialIter
pub fn new(n: u32, k: u32) -> BinomialIter
Create a new BinomialIter
. This will calculate the binomial
coefficient once using the recursive definition.
§Panics
If k > n
Sourcepub fn inc_n(&mut self) -> Option<(u32, u32)>
pub fn inc_n(&mut self) -> Option<(u32, u32)>
Increase n
by one and update the internal state accordingly.
Returns None
when calculating n + 1
choose k
would overflow,
otherwise Some((n + 1, binom))
.
Sourcepub fn dec_n(&mut self) -> Option<(u32, u32)>
pub fn dec_n(&mut self) -> Option<(u32, u32)>
Decrease n
by one and update the internal state accordingly.
Returns None
when calculating n - 1
choose k
would overflow or
n - 1 < k
, otherwise Some((n - 1, binom))
.
Source§impl BinomialIter
impl BinomialIter
Sourcepub fn iter_inc_n(self) -> IncNIter ⓘ
pub fn iter_inc_n(self) -> IncNIter ⓘ
Returns an iterator which wraps this BinomialIter
, returns the current
value of n
and binom
on the first call to next
and the result of
calling inc_n
on the underlying BinominalIter
for subsequent calls
to next.
Source§impl BinomialIter
impl BinomialIter
Sourcepub fn iter_dec_n(self) -> DecNIter ⓘ
pub fn iter_dec_n(self) -> DecNIter ⓘ
Returns an iterator which wraps this BinomialIter
, returns the current
value of n
and binom
on the first call to next
and the result of
calling dec_n
on the underlying BinominalIter
for subsequent calls
to next.
Source§impl BinomialIter
impl BinomialIter
Sourcepub fn iter_inc_k(self) -> IncKIter ⓘ
pub fn iter_inc_k(self) -> IncKIter ⓘ
Returns an iterator which wraps this BinomialIter
, returns the current
value of k
and binom
on the first call to next
and the result of
calling inc_k
on the underlying BinominalIter
for subsequent calls
to next.
Source§impl BinomialIter
impl BinomialIter
Sourcepub fn iter_dec_k(self) -> DecKIter ⓘ
pub fn iter_dec_k(self) -> DecKIter ⓘ
Returns an iterator which wraps this BinomialIter
, returns the current
value of k
and binom
on the first call to next
and the result of
calling dec_k
on the underlying BinominalIter
for subsequent calls
to next.
Trait Implementations§
Source§impl Clone for BinomialIter
impl Clone for BinomialIter
Source§fn clone(&self) -> BinomialIter
fn clone(&self) -> BinomialIter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more