Struct rgsl::types::combination::Combination
source · [−]pub struct Combination { /* private fields */ }
Implementations
sourceimpl 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) -> Value
pub fn copy(&self, dest: &mut Combination) -> 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) -> Value
pub fn is_valid(&self) -> 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) -> Value
pub fn next(&mut self) -> 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.
Trait Implementations
sourceimpl Debug for Combination
impl Debug for Combination
Auto Trait Implementations
impl RefUnwindSafe for Combination
impl !Send for Combination
impl !Sync for Combination
impl Unpin for Combination
impl UnwindSafe for Combination
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more