Struct Comb

Source
pub struct Comb { /* private fields */ }
Expand description

A struct for pre-calculating factorials and their modular inverses, useful for efficient combination and permutation calculations under mod.

Implementations§

Source§

impl Comb

Source

pub fn new(mod_value: u64, max_fact: usize) -> Comb

Creates a new Comb instance, pre-calculating factorials and their modular inverses up to max_fact.

This pre-computation allows for fast calculation of combinations and permutations modulo mod_value.

§Arguments
  • mod_value - The modulus to use for calculations.
  • max_fact - The maximum number for which factorials and inverse factorials will be pre-calculated. This determines the range of n that can be used in nCr and nPr without requiring further calculations.
§Panics

Panics if modulus is not prime.

Source

pub fn nPr(&self, n: u64, r: u64) -> u64

Calculates nPr (n permutations of r) under mod.

§Arguments
  • n - The total number of items.
  • r - The number of items to choose.
§Panics

Panics if n is less than r or n > max_fact.

Source

pub fn nCr(&self, n: u64, r: u64) -> u64

Calculates nCr (n combinations of r) under mod.

§Arguments
  • n - The total number of items.
  • r - The number of items to choose.
§Panics

Panics if n is less than r or n > max_fact.

Auto Trait Implementations§

§

impl Freeze for Comb

§

impl RefUnwindSafe for Comb

§

impl Send for Comb

§

impl Sync for Comb

§

impl Unpin for Comb

§

impl UnwindSafe for Comb

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