This crate provide generic cartesian product iterator, combination iterator, and permutation iterator.
Three main functionalities
- Cartesian product
- Combination
- Permutation
Two different style on every functionality
This crate provide two implementation style
- Iterator style
- Callback function style
Easily share result
- Every functionalities can take Rc<RefCell<>> to store result.
- An iterator that return owned value.
- Every callback style function can take Arc<RwLock<>> to store result.
Easy usage
Three built-in traits that add cart_prod, combination, and permutation functionality to slice/array, Rc<RefCell<&mut[T]>>, and more.
Unreach raw performance with unsafe
Every functionalities can take raw mutable pointer to store result.
Example
- Getting k-permutation where k is 3 and n is 5.
use ;
let mut data = &;
let mut counter = 1;
data.combination.for_each;
- Cartesian product of set of 3, 4, and 5 respectively
use ;
let mut domains : &= &;
println!;
new.into_iter.for_each;
println!;
cartesian_product;
- Easy sharable result
use RefCell;
use Rc;
use Instant;
use CartesianProduct;
let mut counter = 0;
let timer = now;
let data : &= &;
let mut result = vec!;
let shared = new;
.cart_prod.for_each;
println!;
- Unsafely share result example
use Instant;
use Permutation;
let data : & = &;
let mut counter = 0;
let k = 3;
let mut result : = vec!;
// `result` can be share safely anywhere
let shared = result.as_mut_slice as *mut ;
// `shared` can be share as long as `result` is alive
let timer = now;
// unsafe statement may be omit because the permutation trait
// hid it internally. However, keep in mind that it rely
// on a pointer so every operation is still considered unsafe.
unsafe