Skip to content

Commit

Permalink
change ordering (whoops)
Browse files Browse the repository at this point in the history
  • Loading branch information
paultag committed Jan 2, 2025
1 parent e279ee3 commit 15f8648
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ impl Matrix {

/// return the offset into the 1d tree.
fn offset(&self, x: usize, y: usize) -> usize {
(self.side() * y) + x
(self.side() * x) + y
}

/// Return a row of the Matrix
pub fn row(&self, row: usize) -> impl Iterator<Item = bool> {
let start = row * self.side();
let end = start + self.side();
self.0.iter_range(start..end)
}

/// return the value of the bit at (x, y)
Expand Down Expand Up @@ -141,6 +148,25 @@ mod tests {
}
}
}

#[test]
fn matrix_get_row() {
let mut mat = Matrix::new();
mat.grow();

mat.set(5, 1);
mat.set(5, 7);
mat.set(5, 8);

let row = mat.row(5).collect::<Vec<_>>();
assert_eq!(
vec![
false, true, false, false, false, false, false, true, true, false, false, false,
false, false, false, false
],
row
);
}
}

// vim: foldmethod=marker

0 comments on commit 15f8648

Please sign in to comment.