Trait Subfactorial

Source
pub trait Subfactorial {
    // Required method
    fn subfactorial(n: u64) -> Self;
}
Expand description

Computes the subfactorial of a u64. The subfactorial of a non-negative integer $n$ counts the number of derangements of $n$ elements, which are the permutations in which no element is fixed.

Required Methods§

Source

fn subfactorial(n: u64) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Subfactorial for u8

Source§

fn subfactorial(n: u64) -> u8

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Subfactorial for u16

Source§

fn subfactorial(n: u64) -> u16

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Subfactorial for u32

Source§

fn subfactorial(n: u64) -> u32

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Subfactorial for u64

Source§

fn subfactorial(n: u64) -> u64

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Subfactorial for u128

Source§

fn subfactorial(n: u64) -> u128

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Source§

impl Subfactorial for usize

Source§

fn subfactorial(n: u64) -> usize

Computes the subfactorial of a number.

The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.

If the input is too large, the function panics. For a function that returns None instead, try checked_subfactorial.

$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$

$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if the output is too large to be represented.

§Examples

See here.

Implementors§