[−][src]Trait permutator::CartesianProduct
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());
Associated Types
Loading content...Required methods
fn cart_prod(&'a self) -> Self::Producer
Create a cartesian product producer which can be used to iterate over each product.
Implementations on Foreign Types
impl<'a, T> CartesianProduct<'a> for [&'a [T]] where
T: 'a,
[src]
T: 'a,
type Producer = CartesianProductIterator<'a, T>
fn cart_prod(&'a self) -> Self::Producer
[src]
impl<'a, T> CartesianProduct<'a> for Vec<&'a [T]> where
T: 'a,
[src]
T: 'a,
type Producer = CartesianProductIterator<'a, T>
fn cart_prod(&'a self) -> Self::Producer
[src]
Implementors
impl<'a, 'b: 'a, T> CartesianProduct<'a> for CartesianProductIntoCellParams<'b, T> where
T: 'b,
[src]
T: 'b,
type Producer = CartesianProductCellIter<'b, T>
fn cart_prod(&'a self) -> Self::Producer
[src]
impl<'a, 'b: 'a, T> CartesianProduct<'a> for CartesianProductIntoRefParams<'b, T> where
T: 'b,
[src]
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>
fn cart_prod(&'a self) -> Self::Producer
[src]
impl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProduct<'b, T> where
T: 'b,
[src]
T: 'b,
type Producer = SelfCartesianProductIterator<'b, T>
fn cart_prod(&'a self) -> Self::Producer
[src]
impl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProductIntoCellParams<'b, T> where
T: 'b,
[src]
T: 'b,
type Producer = SelfCartesianProductCellIter<'b, T>
fn cart_prod(&'a self) -> Self::Producer
[src]
impl<'a, 'b: 'a, T> CartesianProduct<'a> for SelfCartesianProductIntoRefParams<'b, T> where
T: 'b,
[src]
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.