SudokuInfo

Struct SudokuInfo 

Source
pub struct SudokuInfo<C: Constraint + Clone> { /* private fields */ }
Expand description

Enriches a Sudoku with additional information about which numbers can go into the cells. This is analogous to the pencil markings a human player would make. It is used by Strategies to communicate the results of logical reasoning.

This struct already excludes options which violate the Sudoku’s constraint, unless unprocessed changes have been made.

Implementations§

Source§

impl<C: Constraint + Clone> SudokuInfo<C>

Source

pub fn from_sudoku(sudoku: Sudoku<C>) -> SudokuInfo<C>

Creates a new Sudok info for a Sudoku. The options for all cells that are empty in the provided Sudoku are all valid digits, and the options for cells which are filled in the Sudoku are only the digit in that cell.

Source

pub fn get_cell(&self, column: usize, row: usize) -> SudokuResult<Option<usize>>

Gets the content of the cell at the specified position.

This is syntactic sugar for x.sudoku().grid().get_cell(...).

§Arguments
  • column: The column (x-coordinate) of the desired cell. Must be in the range [0, size[.
  • row: The row (y-coordinate) of the desired cell. Must be in the range [0, size[.
§Errors

If either column or row are not in the specified range. In that case, SudokuError::OutOfBounds is returned.

Source

pub fn enqueue_enter_cell( &mut self, column: usize, row: usize, number: usize, ) -> SudokuResult<()>

Enqueues a number to be assigned to the content of the cell at the specified position on the next update. If the cell is not empty at that point, the old number will be overwritten.

In contrast with enter_cell_no_update, this function never enters the number into the cell right away, so when querying the cell it will still look empty. This is done both for performance reasons and to preserve semantics of only applying a strategy once for strategies which may process the same cell more than once, which is important for the bounded backtracking strategies. To ensure that the state of this is up-to-date, i.e. the new cells are entered and the options are adapted to accomodate for them, call invalidate after you are finished enqueueing changes.

§Arguments
  • column: The column (x-coordinate) of the assigned cell. Must be in the range [0, size[.
  • row: The row (y-coordinate) of the assigned cell. Must be in the range [0, size[.
  • number: The number to assign to the specified cell. Must be in the range [1, size].
§Errors
  • SudokuError::OutOfBounds If either column or row are not in the specified range.
  • SudokuError::InvalidNumber If number is not in the specified range.
Source

pub fn enter_cell_no_update( &mut self, column: usize, row: usize, number: usize, ) -> SudokuResult<()>

Sets the content of the cell at the specified position to the given number. If the cell was not empty, the old number will be overwritten.

In contrast with enter_cell, this method does not remove cell options that are invalidated by the new digit. This is done for performance reasons to allow batching of multiple changes before updating the options. To ensure the cell options are up-to-date, call invalidate after making any changes.

§Arguments
  • column: The column (x-coordinate) of the assigned cell. Must be in the range [0, size[.
  • row: The row (y-coordinate) of the assigned cell. Must be in the range [0, size[.
  • number: The number to assign to the specified cell. Must be in the range [1, size].
§Errors
  • SudokuError::OutOfBounds If either column or row are not in the specified range.
  • SudokuError::InvalidNumber If number is not in the specified range.
Source

pub fn enter_cell( &mut self, column: usize, row: usize, number: usize, ) -> SudokuResult<()>

Sets the content of the cell at the specified position to the given number. If the cell was not empty, the old number will be overwritten.

In contrast with enter_cell_no_update, this method immediately removes all cell options that are invalidated by the new digit.

§Arguments
  • column: The column (x-coordinate) of the assigned cell. Must be in the range [0, size[.
  • row: The row (y-coordinate) of the assigned cell. Must be in the range [0, size[.
  • number: The number to assign to the specified cell. Must be in the range [1, size].
§Errors
  • SudokuError::OutOfBounds If either column or row are not in the specified range.
  • SudokuError::InvalidNumber If number is not in the specified range.
Source

pub fn invalidate(&mut self)

Removes all cell options that have been invalidated by digits entered using enter_cell_no_update which have not yet been processed. If there are no pending digits, nothing will be done.

Source

pub fn get_options(&self, column: usize, row: usize) -> SudokuResult<&USizeSet>

Gets a USizeSet of the possible digits that can be entered into the cell at the given position according to this grid info.

Note that, because options are adapted to new digits lazily, this operation may require changes to this instance, namely if digits were changed since the last call to get_options or get_options_mut. This means a mutable reference to this instance is required.

§Arguments
  • column: The column (x-coordinate) of the desired cell. Must be in the range [0, size[.
  • row: The row (y-coordinate) of the desired cell. Must be in the range [0, size[.
§Errors

If either column or row are not in the specified range. In that case, SudokuError::OutOfBounds is returned.

Source

pub fn get_options_mut( &mut self, column: usize, row: usize, ) -> SudokuResult<&mut USizeSet>

Gets a mutable reference to the USizeSet that tracks the possible digits that can be entered into the cell at the given position according to this grid info.

Note that, because options are adapted to new digits lazily, this operation may require changes to this instance, namely if digits were changed since the last call to get_options or get_options_mut.

§Arguments
  • column: The column (x-coordinate) of the desired cell. Must be in the range [0, size[.
  • row: The row (y-coordinate) of the desired cell. Must be in the range [0, size[.
§Errors

If either column or row are not in the specified range. In that case, SudokuError::OutOfBounds is returned.

Source

pub fn size(&self) -> usize

Gets the total size of the grid for which this instance tracks information on one axis (horizontally or vertically). Since grids are always squares, this is guaranteed to be valid for both axes.

Source

pub fn cell_options(&self) -> &Vec<USizeSet>

Gets a read-only reference to the vector storing the options for every cell in a USizeSet. The cells are in eft-to-right, top-to-bottom order, where rows are together.

Source

pub fn cell_options_mut(&mut self) -> &mut Vec<USizeSet>

Gets a mutable reference to the vector storing the options for every cell in a USizeSet. The cells are in left-to-right, top-to-bottom order, where rows are together.

Source

pub fn block_width(&self) -> usize

Gets the width (number of columns) of one sub-block of the Sudoku. To ensure a square grid, this is also the number of blocks that compose the grid vertically.

This is syntactic sugar for x.sudoku().grid().block_width().

Source

pub fn block_height(&self) -> usize

Gets the height (number of rows) of one sub-block of the Sudoku. To ensure a square grid, this is also the number of blocks that compose the grid horizontally.

This is syntactic sugar for x.sudoku().grid().block_height().

Source

pub fn assign(&mut self, other: &SudokuInfo<C>) -> SudokuResult<()>

Assigns the content of another grid info to this one, that is, after the operation this grid info will equal other. The dimensions must be equivalent.

§Errors

If other has different dimensions to this instance. In that case, SudokuError::InvalidDimensions is returned.

Source

pub fn sudoku(&self) -> &Sudoku<C>

Gets the Sudoku for which this Sudoku info stores additional information.

Source

pub fn sudoku_mut(&mut self) -> &mut Sudoku<C>

Gets a mutable reference to the Sudoku for which this Sudoku info stores additional information.

Source

pub fn intersect_assign(&mut self, other: &SudokuInfo<C>) -> SudokuResult<bool>

Intersects this Sudoku info with the given other one, implying that all information of both is correct. All cells that are filled in in either will be written in the result and only options that are present in both will be retained. Note that contradictions (different digits in this and the other Sudoku info) will result in the cell being cleared and all options being removed.

Source

pub fn union_assign(&mut self, other: &SudokuInfo<C>) -> SudokuResult<bool>

Unifies this Sudoku info with the given other one, implying that all information of both could be correct. Options present in at least one will be put in the result and digits are only retained if they are present in both (unless the other does not have any options for that cell). Note that contradictions (different digits in this and the other Sudoku info) will result in the cell being cleared and both numbers being put in the option set.

Trait Implementations§

Source§

impl<C: Clone + Constraint + Clone> Clone for SudokuInfo<C>

Source§

fn clone(&self) -> SudokuInfo<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Constraint + Clone> PartialEq for SudokuInfo<C>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<C> Freeze for SudokuInfo<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for SudokuInfo<C>
where C: RefUnwindSafe,

§

impl<C> Send for SudokuInfo<C>
where C: Send,

§

impl<C> Sync for SudokuInfo<C>
where C: Sync,

§

impl<C> Unpin for SudokuInfo<C>
where C: Unpin,

§

impl<C> UnwindSafe for SudokuInfo<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V