Expand description
A module that perform everything in copy fashion. There is no Heap permutation family function in here because that function family already return a slice of value.
The additional constraint here is T must implement copy.
The benefit of using this module is the input and output
of each functionality will always in the same format.
So there will be no &[&&&T] like in parent module
when you perform a cartesian_product then combination
then heap_permutation function.
The downside is that if T is expensive to copy then
there will be performance cost to pay.
General rule is that if type T in slice like &[T]
is primitive type, this module will likely have no
performance different, thus easier to use because
there’ll be no such ***x[0] syntax but if type T is
a complex type like struct then it cannot be directly
used in this module. There’ll be some situation that required
usage of this module. For example, in some case, a common Vec
to store result from both combination result and those that
is result from sequence of operation like combination then
permutation. This cannot be done with the non-copy version
because the result of single operation will be &[&T] but
two operations will be &[&&T] which has different type.
To avoid such case, create another Vec that hold every T
then create another Vec that hold usize pointed to each
element in prior Vec. Now we have a Vec that store primitive
type thust can be used in this module.
Another way to do the same thing but doesn’t have an indirection
like actual_data[pointers[i]] to access data is to create
a Vec<&T> and every element in this Vec is just a ref to
another element in Vecref_vec[i].
The only restriction with later approach is T must be sized.
Note: All Iterator that return an owned item
still return the same owned item, e.g. Vec
Structs§
- Cartesian
Product Cell Iter - Generate a cartesian product between given domains into Rc<RefCell<&mut [T]>>
in an iterator style.
The struct implement
Iteratortrait so it can be used asIterator. The struct provide into_iter() function that return itself. - Cartesian
Product Iterator - Generate a cartesian product between given domains in an iterator style.
The struct implement
Iteratortrait so it can be used inIteratorstyle. The struct provide into_iter() function that return itself. - Cartesian
Product RefIter - An unsafe way to generate a cartesian product between given domains
into *mut [T] in an iterator style.
The struct implement
Iteratortrait so it can be used asIterator. The struct provide into_iter() function that return itself. - Combination
Cell Iter - Deprecated
- Combination
Iterator - Deprecated
- Combination
RefIter - Deprecated
- Gosper
Combination Cell Iter - Deprecated
- Gosper
Combination Iterator - Deprecated
- Gosper
Combination RefIter - Deprecated
- KPermutation
Cell Iter - k-Permutation over data of length “n” where
kmust be less thann. It’ll attempt to permute given data by pickkelements out ofndata. It use Gosper algorithm to pick the elements. It then use Heap’s algorithm to permute thosekelements and return each permutation back to caller by given Rc<RefCell<&mut [&T]>> parameter to new method of KPermutationCellIter. - KPermutation
Iterator - k-Permutation over data of length n where k must be
less than n.
It’ll attempt to permute given data by pick
kelements out of data. It use Gosper algorithm to pick the elements. It then use Heap’s algorithm to permute thosekelements and return each permutation back to caller. - KPermutation
RefIter - k-Permutation over data of length “n” where
kmust be less thannand store result into mutable pointer. It’ll attempt to permute given data by pickkelements out ofndata. It use Gosper algorithm to pick the elements. It then use Heap’s algorithm to permute thosekelements and return each permutation back to caller by given *mut [&T]>> parameter to new method of KPermutationRefIter. - Large
Combination Cell Iter - Create a combination iterator. The result is lexicographic ordered if input is lexicorgraphic ordered.
- Large
Combination Iterator - Create a combination iterator. The result is lexicographic ordered if input is lexicorgraphic ordered.
- Large
Combination RefIter - Create an unsafe combination iterator that return result to mutable pointer. The result is lexicographic ordered if input is lexicorgraphic ordered.
- Self
Cartesian Product Cell Iter - Generate a cartesian product on itself in an iterator style.
The struct implement
Iteratortrait so it can be used inIteratorstyle. The struct provide into_iter() function that return itself. - Self
Cartesian Product Iterator - Generate a cartesian product on itself in an iterator style.
The struct implement
Iteratortrait so it can be used inIteratorstyle. The struct provide into_iter() function that return itself. - Self
Cartesian Product RefIter - Generate a cartesian product on itself in an iterator style.
The struct implement
Iteratortrait so it can be used inIteratorstyle. The struct provide into_iter() function that return itself. - XPermutation
Cell Iter - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
- XPermutation
Iterator - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
- XPermutation
RefIter - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
Traits§
- Cartesian
Product - Create a cartesian product out of
T. For example, - Combination
- Create a combination out of
TNormally, it take a[T]orVec<T>to create a combination. - Permutation
- Create a permutation iterator that permute data in place.
Built-in implementation return an object of
HeapPermutation for slice/array and Vec.
It return an object of HeapPermutationCellIter
on data type of
Rc<RefCell<&mut [T]>>.
Functions§
- cartesian_
product - Create a cartesian product over given slice. The result will be a slice
of
T. - cartesian_
product_ cell - Similar to safe cartesian_product function except the way it return the product. It return result through Rc<RefCell<>> to mutable slice of result. It’ll notify caller on each new result via empty callback function.
- cartesian_
product_ sync - Similar to safe cartesian_product function except the way it return the product. It return result through Rc<RefCell<>> to mutable slice of result. It’ll notify caller on each new result via empty callback function.
- combination
- Deprecated
- combination_
cell - Deprecated
- combination_
sync - Deprecated
- get_
cartesian_ for - Get a cartesian product at specific location.
If
objectsis [1, 2, 3] and degree is 2 then all possible result is [1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3] - get_
permutation_ for - Get permutation at specific location.
If
objectsis [1, 2, 3, 4] anddegreeis 2 then all possible permutation will be [1, 2], [1, 3], [1, 4], [2, 1], [2, 3], [2, 4], [3, 1], [3, 2], [3, 4], [4, 1], [4, 2], [4, 3]. - get_
permutation_ size - Calculate all possible number of permutation. It’s equals to size!/(size - 1).
- k_
permutation - Generate k-permutation over slice of
d. For example: d = &[1, 2, 3]; k = 2. The result will be [1, 2], [2, 1], [1, 3], [3, 1], [2, 3], [3, 2] - k_
permutation_ cell - Similar to safe k_permutation function except the way it return the permutation. It return result through mutable pointer to result assuming the pointer is valid. It’ll notify caller on each new result via empty callback function.
- k_
permutation_ sync - Similar to safe k_permutation function except the way it return the permutation. It return result through mutable pointer to result assuming the pointer is valid. It’ll notify caller on each new result via empty callback function.
- large_
combination - Generate a r-combination from given domain and call callback function on each combination.
- large_
combination_ cell - Generate a r-combination from given domain and call callback function on each combination.
- large_
combination_ sync - Generate a r-combination from given domain and call callback function on each combination.
- self_
cartesian_ product - Create a cartesian product over itself. The result will be a slice
of
T. - self_
cartesian_ product_ cell - Similar to safe cartesian_product function except the way it return the product. It return result through Rc<RefCell<>> to mutable slice of result. It’ll notify caller on each new result via empty callback function.
- self_
cartesian_ product_ sync - Similar to safe self_cartesian_product function except the way it return the product. It return result through Arc<RwLock<>> to mutable slice of result. It’ll notify caller on each new result via empty callback function.
- unsafe_
cartesian_ ⚠product - Similar to safe cartesian_product function except the way it return the product. It return result through mutable pointer to result assuming the pointer is valid. It’ll notify caller on each new result via empty callback function.
- unsafe_
combination ⚠ - Deprecated
- unsafe_
k_ ⚠permutation - Similar to safe k_permutation function except the way it return the permutation. It return result through mutable pointer to result assuming the pointer is valid. It’ll notify caller on each new result via empty callback function.
- unsafe_
large_ ⚠combination - Generate a r-combination from given domain and call callback function on each combination.
- unsafe_
self_ ⚠cartesian_ product - Similar to safe self_cartesian_product function except the way it return the product. It return result through mutable pointer to result assuming the pointer is valid. It’ll notify caller on each new result via empty callback function.
- unsafe_
x_ ⚠permutation - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
- x_
permutation - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
- x_
permutation_ cell - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
- x_
permutation_ sync - A lexicographic ordered permutation based on “Algoritm X” published by Donald E. Knuth. page 20.
Type Aliases§
- Cartesian
Product Into Cell Params - A type that represent a cartesian product of the slice over slices and return result into Rc<RefCell<&mut [&T]>> by using CartesianProductCellIter
- Cartesian
Product Into RefParams - A type that used exclusively for trait CartesianProduct. It return CartesianProductRefIter.
- Combination
Into Cell Params - A pair of source and sink to get a sharable combination.
- Combination
Into RefParams - A pair of source and sink to get a sharable combination.
- KPermutation
Into Cell Params - A tuples of 3 parameters that allow
Permutationtrait to create k-permutation iterator from it. - KPermutation
Into RefParams - A tuple of 3 parameters that allow
Permutationtrait to create k-permutation ref iterator from it. - KPermutation
Params - A pair of parameter that allow
Permutationtrait to create k-permutation iterator from it. - Self
Cartesian Product - A type that used exclusively for trait CartesianProduct. It return SelfCartesianProductIterator.
- Self
Cartesian Product Into Cell Params - A type that used exclusively for trait CartesianProduct. It return SelfCartesianProductCellIter.
- Self
Cartesian Product Into RefParams - A type that used exclusively for trait CartesianProduct. It return SelfCartesianProductRefIter.