safety considerations
This commit is contained in:
parent
9d157745d9
commit
4f191d8689
15
src/main.rs
15
src/main.rs
@ -204,7 +204,7 @@ impl SField {
|
||||
|
||||
#[inline(always)]
|
||||
fn print(&self) {
|
||||
for i in 0..self.size * self.size {
|
||||
for i in 0..self.num_fields {
|
||||
if i != 0 && i % self.size == 0 {
|
||||
println!();
|
||||
}
|
||||
@ -273,10 +273,12 @@ impl SField {
|
||||
fn put_valid_nr(&mut self) -> bool {
|
||||
let current_nr = self.get_field_at_pos(self.pos);
|
||||
|
||||
// safety:
|
||||
// self.possible_vals is initialized with self.size * self.size
|
||||
// so self.pos can safely be used to index here
|
||||
let possible_vals = unsafe { self.possible_values.get_unchecked(self.pos) };
|
||||
|
||||
for idx in 0..possible_vals.len() {
|
||||
let nr = unsafe { possible_vals.get_unchecked(idx) };
|
||||
for nr in possible_vals.iter() {
|
||||
if *nr <= current_nr {
|
||||
continue;
|
||||
}
|
||||
@ -308,11 +310,18 @@ impl SField {
|
||||
|
||||
#[inline(always)]
|
||||
fn is_fixed(&self) -> bool {
|
||||
// safety: self.pos can be used to index the field unchecked
|
||||
// since the only methods modifying self.pos are
|
||||
// `next()` and `prev()` and they do bounds checking
|
||||
unsafe { *self.fixed.get_unchecked(self.pos) == 1 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn get_field_at_pos(&self, pos: usize) -> usize {
|
||||
// safety:
|
||||
// TODO
|
||||
// would need to mathematically explain that the calculations in
|
||||
// get_row(), get_col() and get_block() can never exceed 0..self.num_fields
|
||||
unsafe { *self.field.get_unchecked(pos) }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user