Skip to main content

GridQuorumSet

Struct GridQuorumSet 

Source
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>
where ID: Ord + Clone,

Source

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.

Source

pub fn grid(&self) -> &[Vec<ID>]

Returns the grid, as its rows.

Source

pub fn rule(&self) -> GridRule

Returns whether an accepted set holds a full row or one ID of each row.

Trait Implementations§

Source§

impl<ID: Clone> Clone for GridQuorumSet<ID>

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<ID: Debug> Debug for GridQuorumSet<ID>

Source§

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

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

impl<ID: Eq> Eq for GridQuorumSet<ID>

Source§

impl<ID: PartialEq> PartialEq for GridQuorumSet<ID>

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<ID> QuorumIntersection<GridQuorumSet<ID>> for GridQuorumSet<ID>
where ID: Ord + Clone,

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 OnePerRow quorum exactly when it holds a full row. A set without a full row misses an ID of each row, and these IDs form a OnePerRow quorum 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>

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.

Source§

impl<ID> QuorumSet for GridQuorumSet<ID>
where ID: Ord + Clone,

Source§

type Id = ID

Node ID type in this quorum set.
Source§

type Iter = IntoIter<ID>

Iterator over every voter ID tracked by this quorum set. Read more
Source§

fn is_quorum<'a, I>(&self, ids: I) -> bool
where ID: 'a, I: Iterator<Item = &'a ID> + Clone,

Return true if the candidate IDs satisfy this quorum rule. Read more
Source§

fn ids(&self) -> Self::Iter

Return all voter IDs in this quorum set.
Source§

impl<ID: PartialEq> StructuralPartialEq for GridQuorumSet<ID>

Auto Trait Implementations§

§

impl<ID> Forget for GridQuorumSet<ID>

§

impl<ID> Freeze for GridQuorumSet<ID>
where Vec<Vec<ID>>: Freeze,

§

impl<ID> RefUnwindSafe for GridQuorumSet<ID>
where Vec<Vec<ID>>: RefUnwindSafe,

§

impl<ID> Send for GridQuorumSet<ID>
where Vec<Vec<ID>>: Send,

§

impl<ID> Sync for GridQuorumSet<ID>
where Vec<Vec<ID>>: Sync,

§

impl<ID> Unpin for GridQuorumSet<ID>
where Vec<Vec<ID>>: Unpin,

§

impl<ID> UnsafeUnpin for GridQuorumSet<ID>
where Vec<Vec<ID>>: UnsafeUnpin,

§

impl<ID> UnwindSafe for GridQuorumSet<ID>
where Vec<Vec<ID>>: 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> Same for T

Source§

type Output = T

Should always be Self
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.