Don't use DMat
This commit is contained in:
parent
e7168b8b43
commit
6d85e2b944
18
src/lib.rs
18
src/lib.rs
@ -141,17 +141,15 @@ enum Mark {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct MarkMatrix {
|
struct MarkMatrix {
|
||||||
n: usize,
|
marks: SquareMatrix<Mark>
|
||||||
marks: DMat<Mark>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MarkMatrix {
|
impl MarkMatrix {
|
||||||
fn new(n: usize) -> MarkMatrix {
|
fn new(n: usize) -> MarkMatrix {
|
||||||
MarkMatrix {n: n,
|
MarkMatrix {marks: SquareMatrix::from_row_vec(n, (0..n*n).map(|_| Mark::None).collect())}
|
||||||
marks: DMat::from_elem(n, n, Mark::None)}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn n(&self) -> usize { self.n }
|
fn n(&self) -> usize { self.marks.n() }
|
||||||
|
|
||||||
fn toggle_star(&mut self, pos: (usize, usize)) {
|
fn toggle_star(&mut self, pos: (usize, usize)) {
|
||||||
if self.is_star(pos) {
|
if self.is_star(pos) {
|
||||||
@ -192,7 +190,7 @@ impl MarkMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_first_star_in_row(&self, row: usize) -> Option<usize> {
|
fn find_first_star_in_row(&self, row: usize) -> Option<usize> {
|
||||||
for col in 0..self.n {
|
for col in 0..self.n() {
|
||||||
if self.is_star((row, col)) {
|
if self.is_star((row, col)) {
|
||||||
return Some(col);
|
return Some(col);
|
||||||
}
|
}
|
||||||
@ -201,7 +199,7 @@ impl MarkMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_first_prime_in_row(&self, row: usize) -> Option<usize> {
|
fn find_first_prime_in_row(&self, row: usize) -> Option<usize> {
|
||||||
for col in 0..self.n {
|
for col in 0..self.n() {
|
||||||
if self.is_prime((row, col)) {
|
if self.is_prime((row, col)) {
|
||||||
return Some(col);
|
return Some(col);
|
||||||
}
|
}
|
||||||
@ -210,7 +208,7 @@ impl MarkMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_first_star_in_col(&self, col: usize) -> Option<usize> {
|
fn find_first_star_in_col(&self, col: usize) -> Option<usize> {
|
||||||
for row in 0..self.n {
|
for row in 0..self.n() {
|
||||||
if self.is_star((row, col)) {
|
if self.is_star((row, col)) {
|
||||||
return Some(row);
|
return Some(row);
|
||||||
}
|
}
|
||||||
@ -219,8 +217,8 @@ impl MarkMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear_primes(&mut self) {
|
fn clear_primes(&mut self) {
|
||||||
for row in 0..self.n {
|
for row in 0..self.n() {
|
||||||
for col in 0..self.n {
|
for col in 0..self.n() {
|
||||||
if let Mark::Prime = self.marks[(row, col)] {
|
if let Mark::Prime = self.marks[(row, col)] {
|
||||||
self.marks[(row, col)] = Mark::None;
|
self.marks[(row, col)] = Mark::None;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user