pub struct MultiSet { /* private fields */ }Implementations§
Source§impl MultiSet
impl MultiSet
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 multiset with parameters n, k. The multiset is not
initialized and its elements are undefined. Use the function Self::new_with_init if you
want to create a multiset which is initialized to the lexicographically first multiset
element. A null pointer is returned if insufficient memory is available to create the
multiset.
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 multiset with parameters n, k and initializes it to the lexicographically first multiset element. A null pointer is returned if insufficient memory is available to create the multiset.
Sourcepub fn init_first(&mut self)
pub fn init_first(&mut self)
This function initializes the multiset c to the lexicographically first multiset element, i.e. 0 repeated k times.
Sourcepub fn init_last(&mut self)
pub fn init_last(&mut self)
This function initializes the multiset c to the lexicographically last multiset element, i.e. n-1 repeated k times.
Sourcepub fn copy(&self, dest: &mut MultiSet) -> Result<(), Value>
pub fn copy(&self, dest: &mut MultiSet) -> Result<(), Value>
This function copies the elements of the multiset self into the multiset dest. The two
multisets 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 multiset c. 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 multiset self.
Sourcepub fn data(&self) -> &[usize]
pub fn data(&self) -> &[usize]
This function returns a pointer to the array of elements in the multiset self.
Sourcepub fn data_mut(&mut self) -> &mut [usize]
pub fn data_mut(&mut self) -> &mut [usize]
This function returns a pointer to the array of elements in the multiset self.
Sourcepub fn valid(&self) -> Result<(), Value>
pub fn valid(&self) -> Result<(), Value>
This function checks that the multiset self is valid. The k elements should lie in the range 0 to n-1, with each value occurring in non-decreasing order.
Returns OK(()) if valid.
Sourcepub fn next(&mut self) -> Result<(), Value>
pub fn next(&mut self) -> Result<(), Value>
This function advances the multiset self to the next multiset element in lexicographic order
and returns Ok(()). If no further multisets elements are available it returns
Err(Value::Failure) and leaves self unmodified. Starting with the first
multiset and repeatedly applying this function will iterate through all possible multisets
of a given order.
Sourcepub fn prev(&mut self) -> Result<(), Value>
pub fn prev(&mut self) -> Result<(), Value>
This function steps backwards from the multiset self to the previous multiset element in
lexicographic order, returning Value::Success. If no previous multiset is available it
returns Value::Failure and leaves self unmodified.