pub struct Combination { /* private fields */ }Implementations§
Source§impl Combination
impl Combination
Sourcepub fn new(n: usize, k: usize) -> Option<Self>
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.
Sourcepub fn new_with_init(n: usize, k: usize) -> Option<Self>
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.
Sourcepub fn init_first(&mut self)
pub fn init_first(&mut self)
This function initializes the combination c to the lexicographically first combination, i.e. (0,1,2,…,k-1).
Sourcepub fn init_last(&mut self)
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).
Sourcepub fn copy(&self, dest: &mut Combination) -> Result<(), Value>
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.
Sourcepub fn get(&self, i: usize) -> usize
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.
Sourcepub fn k(&self) -> usize
pub fn k(&self) -> usize
This function returns the number of elements (k) in the combination self.
pub fn as_slice(&self) -> &[usize]
pub fn as_mut_slice(&mut self) -> &mut [usize]
Sourcepub fn is_valid(&self) -> Result<(), Value>
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.
Sourcepub fn next(&mut self) -> Result<(), Value>
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.