Refactor Coverage

This commit is contained in:
Michael Neumann 2019-04-07 11:19:54 +02:00
parent 44847c04e1
commit 16bc0a7cbd
2 changed files with 14 additions and 12 deletions

View File

@ -4,19 +4,12 @@ use fixedbitset::FixedBitSet;
#[derive(Debug)] #[derive(Debug)]
pub struct Coverage { pub struct Coverage {
n: usize, n: usize,
/// A bit is set, if the row is covered.
rows: FixedBitSet, rows: FixedBitSet,
/// A bit is set, if the column is covered.
columns: FixedBitSet, columns: FixedBitSet,
} }
fn is_bitset_clear(bitset: &FixedBitSet) -> bool {
for elm in bitset.as_slice().iter() {
if *elm != 0 {
return false;
}
}
return true;
}
impl Coverage { impl Coverage {
#[inline] #[inline]
pub fn n(&self) -> usize { pub fn n(&self) -> usize {
@ -151,7 +144,16 @@ impl Coverage {
self.columns.clear(); self.columns.clear();
} }
pub fn is_clear(&self) -> bool { pub fn all_uncovered(&self) -> bool {
is_bitset_clear(&self.rows) && is_bitset_clear(&self.columns) is_bitset_clear(&self.rows) && is_bitset_clear(&self.columns)
} }
} }
fn is_bitset_clear(bitset: &FixedBitSet) -> bool {
for elm in bitset.as_slice().iter() {
if *elm != 0 {
return false;
}
}
return true;
}

View File

@ -82,7 +82,7 @@ where
assert!(marks.n() == n); assert!(marks.n() == n);
assert!(cov.n() == n); assert!(cov.n() == n);
debug_assert!(cov.is_clear()); debug_assert!(cov.all_uncovered());
cov.iter_uncovered_row_column_and_cover(|pos| { cov.iter_uncovered_row_column_and_cover(|pos| {
if c.is_element_zero(pos) { if c.is_element_zero(pos) {
@ -575,7 +575,7 @@ fn test_solve_equal_rows_stepwise() {
let mut coverage = Coverage::new(weights.n()); let mut coverage = Coverage::new(weights.n());
let next_step = step2(&weights, &mut marks, &mut coverage); let next_step = step2(&weights, &mut marks, &mut coverage);
assert_eq!(Step::Step3, next_step); assert_eq!(Step::Step3, next_step);
assert!(coverage.is_clear()); assert!(coverage.all_uncovered());
assert!(marks.is_star(pos(0, 0))); assert!(marks.is_star(pos(0, 0)));
assert!(marks.is_star(pos(1, 1))); assert!(marks.is_star(pos(1, 1)));