pub struct Combination { /* private fields */ }

Implementations§

source§

impl Combination

source

pub fn new(n: usize, k: usize) -> Option<Self>

This function allocates memory for a new combination with parameters n, k. The combination is not initialized and its elements are undefined. Use the function Combination::new_init_first if you want to create a combination which is initialized to the lexicographically first combination. A null pointer is returned if insufficient memory is available to create the combination.

source

pub fn new_with_init(n: usize, k: usize) -> Option<Self>

This function allocates memory for a new combination with parameters n, k and initializes it to the lexicographically first combination. A null pointer is returned if insufficient memory is available to create the combination.

source

pub fn init_first(&mut self)

This function initializes the combination c to the lexicographically first combination, i.e. (0,1,2,…,k-1).

source

pub fn init_last(&mut self)

This function initializes the combination c to the lexicographically last combination, i.e. (n-k,n-k+1,…,n-1).

source

pub fn copy(&self, dest: &mut Combination) -> Result<(), Value>

This function copies the elements of the combination self into the combination dest. The two combinations must have the same size.

source

pub fn get(&self, i: usize) -> usize

This function returns the value of the i-th element of the combination self. If i lies outside the allowed range of 0 to k-1 then the error handler is invoked and 0 is returned.

source

pub fn n(&self) -> usize

This function returns the range (n) of the combination self.

source

pub fn k(&self) -> usize

This function returns the number of elements (k) in the combination self.

source

pub fn as_slice(&self) -> &[usize]

source

pub fn as_mut_slice(&mut self) -> &mut [usize]

source

pub fn is_valid(&self) -> Result<(), Value>

This function checks that the combination self is valid. The k elements should lie in the range 0 to n-1, with each value occurring once at most and in increasing order.

source

pub fn next(&mut self) -> Result<(), Value>

This function advances the combination self to the next combination in lexicographic order and returns Success. If no further combinations are available it returns Failure and leaves self unmodified. Starting with the first combination and repeatedly applying this function will iterate through all possible combinations of a given order.

source

pub fn prev(&mut self) -> Result<(), Value>

This function steps backwards from the combination self to the previous combination in lexicographic order, returning Success. If no previous combination is available it returns Failure and leaves self unmodified.

Trait Implementations§

source§

impl Debug for Combination

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Combination

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.