[][src]Module sudokul::board

board contains data structures which store the state of a sudoku board.

Multiple different data structures are available, depending on your application's needs and performance characteristics. All of these structures implement the board::Board interface.

Generally, to start, it doesn't matter which one you pick, so going with OmniBoard is fine.

use sudokul::board::Board;
use sudokul::board::OmniBoard;
 
fn main() {
  let mut board = OmniBoard::new();

  // use `set_entry` to set individual entries on the board, by (row, column).
  board.set_entry(0, 0, 1);
  board.set_entry(0, 1, 3);
  board.set_entry(0, 2, 5);
 
  // use `entry` to retrieve individual entries on the board, by (row, column).
  let entry01 = board.entry(0, 1);
  assert_eq!(entry01, 3);
 
  // use `row`/`column`/`square` to retrieve views of the board
  let row0 = board.row(0);
  let col0 = board.column(0);
  let sq0 = board.square(0);
  assert_eq!(row0[0], 1);
  assert_eq!(row0[1], 3);
  assert_eq!(row0[2], 5);
  assert_eq!(col0[0], 1);
  assert_eq!(col0[1], 0);
  assert_eq!(sq0[1], 3);
}

Structs

LinearU8Board

LinearU8Board is a mostly useless board, though its included for reference. It should have performance characteristics similar to the NanoBoard, but consumes roughly double the memory because it dedicates an entire u8 to every entry in the board.

NanoBoard

NanoBoard is a Board implementation that focuses on reducing memory usage, at the cost of access performance. Each board requires only 41 bytes of memory.

OmniBoard

OmniBoard is a board which stores pre-baked forms of every possible projection that could be requested, increasing the memory cost of board storage but reducing the time to retrieve that data by, primarily, reducing new allocations.

Traits

Board

Board is a trait which contains the active state of a sudoku board. Entries in the board can be listed by column, row, or square, and can also be obtained by specifying a row/column point. All of these indexes should be 0-indexed, meaning that the lowest row/ column/square is 0 (zero) and the highest is 8 (eight).