Skip to main content

BinomialIter

Struct BinomialIter 

Source
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

Source

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

Source

pub fn n(&self) -> u32

Access the current value of n.

Source

pub fn k(&self) -> u32

Access the current value of k.

Source

pub fn binom(&self) -> u32

Access the current value of n choose k.

Source

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)).

Source

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

pub fn inc_k(&mut self) -> Option<(u32, u32)>

Increase k by one and update the internal state accordingly.

Returns None when calculating n choose k + 1 would overflow or n < k + 1, otherwise Some((k + 1, binom)).

Source

pub fn dec_k(&mut self) -> Option<(u32, u32)>

Decrease k by one and update the internal state accordingly.

Returns None when calculating n choose k - 1 would overflow or k - 1 < 0, otherwise Some((k - 1, binom))

Source§

impl BinomialIter

Source

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

Source

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

Source

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

Source

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

Source§

fn clone(&self) -> BinomialIter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BinomialIter

Source§

impl Eq for BinomialIter

Source§

impl PartialEq for BinomialIter

Source§

fn eq(&self, other: &BinomialIter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BinomialIter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.