Refactor Coverage
This commit is contained in:
parent
44847c04e1
commit
16bc0a7cbd
@ -4,19 +4,12 @@ use fixedbitset::FixedBitSet;
|
||||
#[derive(Debug)]
|
||||
pub struct Coverage {
|
||||
n: usize,
|
||||
/// A bit is set, if the row is covered.
|
||||
rows: FixedBitSet,
|
||||
/// A bit is set, if the column is covered.
|
||||
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 {
|
||||
#[inline]
|
||||
pub fn n(&self) -> usize {
|
||||
@ -151,7 +144,16 @@ impl Coverage {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_bitset_clear(bitset: &FixedBitSet) -> bool {
|
||||
for elm in bitset.as_slice().iter() {
|
||||
if *elm != 0 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ where
|
||||
|
||||
assert!(marks.n() == n);
|
||||
assert!(cov.n() == n);
|
||||
debug_assert!(cov.is_clear());
|
||||
debug_assert!(cov.all_uncovered());
|
||||
|
||||
cov.iter_uncovered_row_column_and_cover(|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 next_step = step2(&weights, &mut marks, &mut coverage);
|
||||
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(1, 1)));
|
||||
|
Loading…
Reference in New Issue
Block a user