pub struct GridQuorumSet<ID> { /* private fields */ }Expand description
A quorum rule that accepts an ID set holding every ID of some row of its grid, or at least one ID of every row.
The grid is a rectangle of distinct IDs, given as its rows. GridRule selects whether an
accepted set holds a full row or one ID of each row.
The rows of a grid are disjoint, so no row holds another, and the minimal quorums of the
FullRow rule are exactly the rows. The minimal quorums of the OnePerRow rule hold one ID
of each row, from any column. Each row meets every OnePerRow quorum of its grid, so the
FullRow rule and the OnePerRow rule of one grid always intersect.
§Examples
use quorum_set::{GridQuorumSet, GridRule, QuorumIntersection, QuorumSet};
let grid = vec![vec![1, 2, 3], vec![4, 5, 6]];
let full_row = GridQuorumSet::new(grid.clone(), GridRule::FullRow).unwrap();
let one_per_row = GridQuorumSet::new(grid, GridRule::OnePerRow).unwrap();
let accepts = full_row.is_quorum([4, 5, 6].iter());
assert!(accepts);
// {1,5} and {3,4} each hold an ID of both rows, from different columns.
let accepts = one_per_row.is_quorum([1, 5].iter());
assert!(accepts);
let accepts = one_per_row.is_quorum([3, 4].iter());
assert!(accepts);
// {1,2,3} holds no ID of row {4,5,6}.
let accepts = one_per_row.is_quorum([1, 2, 3].iter());
assert!(!accepts);
// Every row meets every `OnePerRow` quorum, but row {1,2,3} misses row {4,5,6}.
let intersects = full_row.intersects_with(&one_per_row);
assert_eq!(Some(true), intersects);
let intersects = full_row.intersects_with(&full_row);
assert_eq!(Some(false), intersects);Implementations§
Source§impl<ID> GridQuorumSet<ID>
impl<ID> GridQuorumSet<ID>
Sourcepub fn new(
grid: Vec<Vec<ID>>,
rule: GridRule,
) -> Result<Self, GridQuorumSetError<ID>>
pub fn new( grid: Vec<Vec<ID>>, rule: GridRule, ) -> Result<Self, GridQuorumSetError<ID>>
Builds a rule over grid, given as its rows, that accepts an ID set holding a full row or
one ID of each row, as rule selects.
Returns GridQuorumSetError unless grid has a row and a column, every row is as long
as the first, and no ID is in two cells.
Trait Implementations§
Source§impl<ID: Clone> Clone for GridQuorumSet<ID>
impl<ID: Clone> Clone for GridQuorumSet<ID>
Source§impl<ID: Debug> Debug for GridQuorumSet<ID>
impl<ID: Debug> Debug for GridQuorumSet<ID>
impl<ID: Eq> Eq for GridQuorumSet<ID>
Source§impl<ID: PartialEq> PartialEq for GridQuorumSet<ID>
impl<ID: PartialEq> PartialEq for GridQuorumSet<ID>
Source§impl<ID> QuorumIntersection<GridQuorumSet<ID>> for GridQuorumSet<ID>
Quorum intersection for two grid rules, exact when either rule is GridRule::FullRow.
impl<ID> QuorumIntersection<GridQuorumSet<ID>> for GridQuorumSet<ID>
Quorum intersection for two grid rules, exact when either rule is GridRule::FullRow.
A set meets every quorum of a rule exactly when the other GridRule over the same grid
accepts the set:
- A set meets every row exactly when it holds an ID of every row.
- A set meets every
OnePerRowquorum exactly when it holds a full row. A set without a full row misses an ID of each row, and these IDs form aOnePerRowquorum that the set misses.
Every quorum of a FullRow rule holds one of its rows, and every row is a quorum. A FullRow
rule therefore intersects another rule exactly when each of its rows meets every quorum of the
other rule. The check gives no answer for two OnePerRow rules. A FullRow read rule with a
OnePerRow write rule over one grid, or the reverse, always gets an exact answer.
Source§fn intersects_with(&self, other: &GridQuorumSet<ID>) -> Option<bool>
fn intersects_with(&self, other: &GridQuorumSet<ID>) -> Option<bool>
Return Some(false) when a row of a FullRow rule misses a quorum of the other rule, and
Some(true) otherwise. Return None for two OnePerRow rules.