fn live_neighbor_count(&self, row: u32, column: u32) -> u8 {
            let mut count = 0;
            for delta_row in [self.height - 1, 0, 1].iter().cloned() {
                for delta_col in [self.width - 1, 0, 1].iter().cloned() {
                    if delta_row == 0 && delta_col == 0 {
                        continue;
                    }

                    let neighbor_row = (row + delta_row) % self.height;
                    let neighbor_col = (column + delta_col) % self.width;
                    let idx = self.get_index(neighbor_row, neighbor_col);
                    count += self.cells[idx] as u8;
                }
            }
            count
        }
// The live_neighbor_count method uses deltas and modulo to avoid special casing the edges of the universe with ifs
The live_neighbor_count method uses deltas and modulo to avoid special casing the edges of the universe with ifs
The live_neighbor_count method uses deltas and modulo to avoid special casing the edges of the universe with ifs
fn live_neighbor_count(&self, row: u32, column: u32) -> u8 {
            let mut count = 0;
            for delta_row in [self.height - 1, 0, 1].iter().cloned() {
                for delta_col in [self.width - 1, 0, 1].iter().cloned() {
                    if delta_row == 0 && delta_col == 0 {
                        continue;
                    }
                    let neighbor_row = (row + delta_row) % self.height;
                    let neighbor_col = (column + delta_col) % self.width;
                    let idx = self.get_index(neighbor_row, neighbor_col);
                    count += self.cells[idx] as u8;
                }
            }
            count
        }
fn live_neighbor_count ( & self , row : u32 , column : u32 ) -> u8 { let mut count = 0 ; for delta_row in [ self . height - 1 , 0 , 1 ] . iter ( ) . cloned ( ) { for delta_col in [ self . width - 1 , 0 , 1 ] . iter ( ) . cloned ( ) { if delta_row == 0 && delta_col == 0 { continue ; } let neighbor_row = ( row + delta_row ) % self . height ; let neighbor_col = ( column + delta_col ) % self . width ; let idx = self . get_index ( neighbor_row , neighbor_col ) ; count += self . cells [ idx ] as u8 ; } } count }
The live_neighbor_count method uses deltas and modulo to avoid special casing the edges of the universe with ifs
The live_neighbor_count method uses deltas and modulo to avoid special casing the edges of the universe with ifs
&self
row
u32
column
u32
&self
row
u32
column
u32