Skip to main content

Table

Struct Table 

Source
pub struct Table { /* private fields */ }
Expand description

The variables take one of the listed tuples of values.

Any relation over a few variables can be written this way: a KenKen cage (every tuple with the right sum or product), the allowed colour pairs of two regions, the shifts a worker can take on consecutive days. Propagation is complete: afterwards every value left is part of an allowed tuple whose other values are all still possible. Each run scans the tuples once.

§Examples

use constraint_search::{Domain, Domains, Propagator, Table};

let mut domains = Domains::<u16>::new();
let x = domains.add(u16::range(4));
let y = domains.add(u16::range(4));

// A two-cell cage whose values sum to 5.
let cage = Table::new([x, y], [[2, 3], [3, 2]]);
cage.propagate(&mut domains, &mut Vec::new())?;
assert!(domains[x].values().eq([2, 3]));

Implementations§

Source§

impl Table

Source

pub fn new<T: AsRef<[u32]>>( vars: impl IntoIterator<Item = Var>, tuples: impl IntoIterator<Item = T>, ) -> Self

The constraint that vars take one of tuples, each listing one value per variable.

§Panics

Panics if vars is empty, holds a variable twice, or if a tuple’s length differs from the number of variables.

Source

pub fn tuples(&self) -> impl Iterator<Item = &[u32]>

The allowed tuples.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Table

Source§

impl PartialEq for Table

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<D: Domain> Propagator<D> for Table

Source§

type Scratch = Vec<D>

The values seen in a possible tuple, per variable.

Source§

fn scope(&self) -> &[Var]

The variables the constraint is over. A change to any of them wakes the propagator.
Source§

fn propagate( &self, domains: &mut Domains<D>, supported: &mut Vec<D>, ) -> Result<(), Inconsistent>

Removes the values the constraint rules out, using scratch as working memory. Read more
Source§

impl StructuralPartialEq for Table

Auto Trait Implementations§

§

impl Forget for Table

§

impl Freeze for Table

§

impl Move for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

§

impl UnwindSafe for Table

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.