Trait permutator::CartesianProduct
source · pub trait CartesianProduct<'a> {
type Producer: Iterator;
fn cart_prod(&'a self) -> Self::Producer;
}
Expand description
Create a cartesian product out of T
.
For example,
T
can be a slice of slices so the product can be created between all the slices.T
can be a pair of slice to slices and Rc<RefCell<>> contains a mutable product from slices.
Examples
- Create a cartesian product and return it as new owned value
use std::time::Instant;
use permutator::CartesianProduct;
let mut counter = 0;
let timer = Instant::now();
let data : &[&[u8]]= &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
data.cart_prod().for_each(|p| {
counter += 1;
});
assert_eq!(data.iter().fold(1, |cum, domain| {cum * domain.len()}), counter);
println!("Total {} products done in {:?}", counter, timer.elapsed());
- Create a cartesian product and return result inside Rc<RefCell<>>
use std::cell::RefCell;
use std::rc::Rc;
use std::time::Instant;
use permutator::CartesianProduct;
let mut counter = 0;
let timer = Instant::now();
let data : &[&[u8]]= &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
let mut result = vec![&data[0][0]; data.len()];
let shared = Rc::new(RefCell::new(result.as_mut_slice()));
(data, Rc::clone(&shared)).cart_prod().for_each(|_| {
counter += 1;
});
assert_eq!(data.iter().fold(1, |cum, domain| {cum * domain.len()}), counter);
println!("Total {} products done in {:?}", counter, timer.elapsed());
Required Associated Types
Required Methods
Implementations on Foreign Types
sourceimpl<'a, T> CartesianProduct<'a> for [&'a [T]]where
T: 'a,
impl<'a, T> CartesianProduct<'a> for [&'a [T]]where
T: 'a,
type Producer = CartesianProductIterator<'a, T>
fn cart_prod(&'a self) -> Self::Producer
sourceimpl<'a, T> CartesianProduct<'a> for Vec<&'a [T]>where
T: 'a,
impl<'a, T> CartesianProduct<'a> for Vec<&'a [T]>where
T: 'a,
type Producer = CartesianProductIterator<'a, T>
fn cart_prod(&'a self) -> Self::Producer
Implementors
sourceimpl<'a, 'b: 'a, T> CartesianProduct<'a> for CartesianProductIntoCellParams<'b, T>where
T: 'b,
impl<'a, 'b: 'a, T> CartesianProduct<'a> for CartesianProductIntoCellParams<'b, T>where
T: 'b,
type Producer = CartesianProductCellIter<'b, T>
sourceimpl<'a, 'b: 'a, T> CartesianProduct<'a> for CartesianProductIntoRefParams<'b, T>where
T: 'b,
impl<'a, 'b: 'a, T> CartesianProduct<'a> for CartesianProductIntoRefParams<'b, T>where
T: 'b,
An implementation for convenient use of CartesianProductRefIter
Warning
It hid unsafe object instantiation of CartesianProductRefIter from user but all unsafe conditions are still applied as long as the the life of object itself.
type Producer = CartesianProductRefIter<'b, T>
sourceimpl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProduct<'b, T>where
T: 'b,
impl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProduct<'b, T>where
T: 'b,
type Producer = SelfCartesianProductIterator<'b, T>
sourceimpl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProductIntoCellParams<'b, T>where
T: 'b,
impl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProductIntoCellParams<'b, T>where
T: 'b,
type Producer = SelfCartesianProductCellIter<'b, T>
sourceimpl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProductIntoRefParams<'b, T>where
T: 'b,
impl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProductIntoRefParams<'b, T>where
T: 'b,
An implementation for convenient use of SelfCartesianProductRefIter
Warning
It hid unsafe object instantiation of SelfCartesianProductRefIter from user but all unsafe conditions are still applied as long as the life of object itself.