pub fn new<I, C>(cliques: I) -> Rules
        where I: Iterator<Item=C>, C: Iterator<Item=CellId> {

        fn unique_vec<T, U>(iter: T) -> Vec<U>
            where T: Iterator<Item=U>, U: Ord {
            let mut vec: Vec<_> = iter.collect();
            vec.sort();
            vec.dedup();
            vec.shrink_to_fit();
            vec
        }

        let clique_cells = unique_vec(cliques.map(unique_vec));
        assert!(clique_cells.len() > 0);
        let size = clique_cells[0].len();
        assert!(size > 0);
        assert!(clique_cells.iter().all(|clique| clique.len() == size));
        let mut cell_cliques: Vec<Vec<CliqueId>> = vec![Vec::new(); size*size];
        for (clique_id, clique) in clique_cells.iter().enumerate() {
            let clique_id = CliqueId(clique_id);
            for &CellId(cell_id) in clique.iter() {
                cell_cliques[cell_id].push(clique_id);
            }
        }
        for cliques in cell_cliques.iter_mut() {
            cliques.shrink_to_fit();
        }
        cell_cliques.shrink_to_fit();
        Rules {
            size: size,
            clique_cells: clique_cells,
            cell_cliques: cell_cliques,
        }
    }
/// Creates new set of arbitrary rules.
///
/// This is the most general way to construct a `Rules`. You must pass an iterator
/// of cliques (each clique being represented as an iterator of `CellId`s).
/// The size of the sudoku grid is inferred from the size of the cliques.
///
/// # Panics
///
/// This will panic unless there is at least one clique, and all cliques have the
/// same (non-zero) size.
///
/// # Examples
///
/// ```rust
/// # use rusudoku::rules::*;
/// use rusudoku::grid::CellId;
///
/// let cliques = [
///     [0, 1, 2, 3],
///     [0, 4, 8, 12],
///     [3, 5, 7, 11],
/// ];
/// let cliques = cliques.iter().map(|clique| {
///     clique.iter().cloned().map(CellId)
/// });
/// let rules = Rules::new(cliques);
/// ```
Creates new set of arbitrary rules.
This is the most general way to construct a `Rules`. You must pass an iterator
of cliques (each clique being represented as an iterator of `CellId`s).
The size of the sudoku grid is inferred from the size of the cliques.
Creates new set of arbitrary rules . This is the most general way to construct a ` Rules ` . You must pass an iterator of cliques ( each clique being represented as an iterator of ` CellId ` s ) . The size of the sudoku grid is inferred from the size of the cliques .
pub fn new<I, C>(cliques: I) -> Rules
        where I: Iterator<Item=C>, C: Iterator<Item=CellId> {
        fn unique_vec<T, U>(iter: T) -> Vec<U>
            where T: Iterator<Item=U>, U: Ord {
            let mut vec: Vec<_> = iter.collect();
            vec.sort();
            vec.dedup();
            vec.shrink_to_fit();
            vec
        }
        let clique_cells = unique_vec(cliques.map(unique_vec));
        assert!(clique_cells.len() > 0);
        let size = clique_cells[0].len();
        assert!(size > 0);
        assert!(clique_cells.iter().all(|clique| clique.len() == size));
        let mut cell_cliques: Vec<Vec<CliqueId>> = vec![Vec::new(); size*size];
        for (clique_id, clique) in clique_cells.iter().enumerate() {
            let clique_id = CliqueId(clique_id);
            for &CellId(cell_id) in clique.iter() {
                cell_cliques[cell_id].push(clique_id);
            }
        }
        for cliques in cell_cliques.iter_mut() {
            cliques.shrink_to_fit();
        }
        cell_cliques.shrink_to_fit();
        Rules {
            size: size,
            clique_cells: clique_cells,
            cell_cliques: cell_cliques,
        }
    }
pub fn new < I , C > ( cliques : I ) -> Rules where I : Iterator < Item = C > , C : Iterator < Item = CellId > { fn unique_vec < T , U > ( iter : T ) -> Vec < U > where T : Iterator < Item = U > , U : Ord { let mut vec : Vec < _ > = iter . collect ( ) ; vec . sort ( ) ; vec . dedup ( ) ; vec . shrink_to_fit ( ) ; vec } let clique_cells = unique_vec ( cliques . map ( unique_vec ) ) ; assert ! ( clique_cells len ( ) 0 ) ; let size = clique_cells [ 0 ] . len ( ) ; assert ! ( size 0 ) ; assert ! ( clique_cells iter ( ) all ( clique clique len ( ) size ) ) ; let mut cell_cliques : Vec < Vec < CliqueId > > = vec ! [ Vec new ( ) size size ] ; for ( clique_id , clique ) in clique_cells . iter ( ) . enumerate ( ) { let clique_id = CliqueId ( clique_id ) ; for & CellId ( cell_id ) in clique . iter ( ) { cell_cliques [ cell_id ] . push ( clique_id ) ; } } for cliques in cell_cliques . iter_mut ( ) { cliques . shrink_to_fit ( ) ; } cell_cliques . shrink_to_fit ( ) ; Rules { size : size , clique_cells : clique_cells , cell_cliques : cell_cliques , } }
Creates new set of arbitrary rules.
Creates new set of arbitrary rules .
cliques
I
cliques
I
panics
This will panic unless there is at least one clique, and all cliques have the
same (non-zero) size.
This will panic unless there is at least one clique and all cliques have the same ( non - zero ) size .
examples
None
use rusudoku::rules::*;
None