Clean up.
- Use cloned instead of map. - Use Val instead of i32. - Import module instead of trait.
This commit is contained in:
parent
630f09fc80
commit
f22b271000
@ -24,7 +24,7 @@ impl AllDifferent {
|
||||
pub fn new<'a, I>(vars: I) -> Self
|
||||
where I: IntoIterator<Item=&'a VarToken> {
|
||||
AllDifferent {
|
||||
vars: vars.into_iter().map(|&x| x).collect(),
|
||||
vars: vars.into_iter().cloned().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ extern crate num_rational;
|
||||
extern crate num_traits;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Index;
|
||||
use std::ops;
|
||||
use num_rational::Rational32;
|
||||
|
||||
pub use constraint::Constraint;
|
||||
@ -52,7 +52,7 @@ pub mod constraint;
|
||||
mod linexpr;
|
||||
mod puzzle;
|
||||
|
||||
impl Index<VarToken> for Solution {
|
||||
impl ops::Index<VarToken> for Solution {
|
||||
type Output = Val;
|
||||
fn index(&self, var: VarToken) -> &Val {
|
||||
let VarToken(idx) = var;
|
||||
|
@ -5,7 +5,7 @@ use std::collections::BTreeSet;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::mem;
|
||||
use std::ops::Index;
|
||||
use std::ops;
|
||||
use std::rc::Rc;
|
||||
use bit_set::BitSet;
|
||||
|
||||
@ -82,7 +82,7 @@ impl Candidates {
|
||||
match self {
|
||||
&Candidates::None => Box::new(iter::empty()),
|
||||
&Candidates::Value(val) => Box::new(iter::once(val)),
|
||||
&Candidates::Set(ref rc) => Box::new(rc.iter().map(|x| *x)),
|
||||
&Candidates::Set(ref rc) => Box::new(rc.iter().cloned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -865,7 +865,7 @@ impl<'a> fmt::Debug for PuzzleSearch<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Index<VarToken> for PuzzleSearch<'a> {
|
||||
impl<'a> ops::Index<VarToken> for PuzzleSearch<'a> {
|
||||
type Output = Val;
|
||||
|
||||
/// Get the value assigned to a variable.
|
||||
|
@ -5,12 +5,12 @@
|
||||
|
||||
extern crate puzzle_solver;
|
||||
|
||||
use puzzle_solver::{Puzzle,Solution,VarToken};
|
||||
use puzzle_solver::{Puzzle,Solution,Val,VarToken};
|
||||
|
||||
const SQRT_SIZE: usize = 3;
|
||||
const SIZE: usize = 9;
|
||||
const X: i32 = -1;
|
||||
type Board = [[i32; SIZE + SQRT_SIZE + SIZE]; SIZE + SQRT_SIZE + SIZE];
|
||||
const X: Val = -1;
|
||||
type Board = [[Val; SIZE + SQRT_SIZE + SIZE]; SIZE + SQRT_SIZE + SIZE];
|
||||
type SudokuVars = Vec<Vec<VarToken>>;
|
||||
type SamuraiVars = (SudokuVars, SudokuVars, SudokuVars, SudokuVars, SudokuVars);
|
||||
|
||||
|
@ -19,7 +19,8 @@ fn xkcd_knapsack() {
|
||||
(Ratio::new(3_35, 100), "Side Salad"),
|
||||
(Ratio::new(3_55, 100), "Hot Wings"),
|
||||
(Ratio::new(4_20, 100), "Mozzarella Sticks"),
|
||||
(Ratio::new(5_80, 100), "Sampler Plate") ];
|
||||
(Ratio::new(5_80, 100), "Sampler Plate"),
|
||||
];
|
||||
|
||||
let mut sys = Puzzle::new();
|
||||
let mut vars = Vec::with_capacity(menu.len());
|
||||
|
Loading…
Reference in New Issue
Block a user