permutator 0.1.5

Get a lexicographic cartesian product and lexicographic permutation at any specific index from data. Generate complete lexicographic cartesian product from multiple set of data. Generate complete non-lexicographic combination from data. Generate non-lexicographic k-permutation.
Documentation
permutator-0.1.5 has been yanked.

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

Easy share result

  • Every function 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

Two built-in traits that add combination and permutation functionality to both Vec and slice.

Unreach raw performance with unsafe

Every callback style function can take raw mutable pointer to store result.

Example

  • Getting k-permutation where k is 3 and n is 5.
use permutator::{Combination, Permutation};
let mut data = &[1, 2, 3, 4, 5];
let mut counter = 1;
data.combination(3).for_each(|mut c| {
c.permutation().for_each(|p| {
println!("k-permutation@{}={:?}", counter, p);
counter += 1;
});
});
  • Cartesian product of set of 3, 4, and 5 respectively
use permutator::{CartesianProduct, cartesian_product};
let mut domains : &[&[i32]]= &[&[1, 2], &[3, 4, 5], &[6, 7, 8, 9]];
println!("=== Cartesian product iterative style ===");
CartesianProduct::new(domains).into_iter().for_each(|p| {
println!("{:?}", p);
});
println!("=== cartesian product callback style ===");
cartesian_product(domains, |p| {
// `p` is borrowed a ref to internal variable inside cartesian_product function.
println!("{:?}", p);
});

See