Skip to main content

ExplicitQuorumSet

Struct ExplicitQuorumSet 

Source
pub struct ExplicitQuorumSet<ID> { /* private fields */ }
Expand description

A quorum rule that accepts an ID set holding every ID of one of its listed quorums.

The rule keeps only the minimal quorums. new() sorts the list, drops duplicate quorums, and drops each quorum that holds another listed quorum, because every set that holds the larger quorum also holds the smaller one. Two rules that accept the same sets therefore hold the same list.

Every accepted set holds a listed quorum, so two rules have quorum intersection exactly when every listed quorum of one meets every listed quorum of the other. The check compares each pair of listed quorums. A rule with no listed quorum accepts no set.

Listing quorums costs memory that grows with the policy. Some policies need exponentially many minimal quorums: a majority of n IDs has C(n, n/2 + 1) of them, 126 for 9 IDs and 6435 for 15.

§Examples

use std::collections::BTreeSet;

use quorum_set::{ExplicitQuorumSet, QuorumIntersection, QuorumSet};

// {1,2,3} holds {1,2}, so the rule keeps only {1,2} and {3,4}.
let quorums = [BTreeSet::from([1, 2, 3]), BTreeSet::from([3, 4]), BTreeSet::from([1, 2])];
let rule = ExplicitQuorumSet::new(quorums).unwrap();
assert_eq!(&[BTreeSet::from([1, 2]), BTreeSet::from([3, 4])], rule.quorums());

let accepts = rule.is_quorum([4, 3, 9].iter());
assert!(accepts);
let accepts = rule.is_quorum([1, 3].iter());
assert!(!accepts);

// {3,4} misses {1,2}.
let intersects = rule.intersects_with(&rule);
assert_eq!(Some(false), intersects);

Implementations§

Source§

impl<ID> ExplicitQuorumSet<ID>
where ID: Ord + Clone,

Source

pub fn new<I>(quorums: I) -> Option<Self>
where I: IntoIterator<Item = BTreeSet<ID>>,

Builds a rule that accepts an ID set holding every ID of one of quorums.

Returns None when a listed quorum is empty: every set holds the empty set, so every set, the empty one included, would be a quorum.

Source

pub fn quorums(&self) -> &[BTreeSet<ID>]

Returns the minimal quorums, sorted.

Source

pub fn disjoint_quorums<'a>( &'a self, other: &'a Self, ) -> Option<(&'a BTreeSet<ID>, &'a BTreeSet<ID>)>

Returns the first pair of a listed quorum of self and a listed quorum of other that share no ID, in the order of the two lists, or None when every pair meets.

Such a pair shows two disjoint quorums, so None means the two rules have quorum intersection.

Trait Implementations§

Source§

impl<ID: Clone> Clone for ExplicitQuorumSet<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 ExplicitQuorumSet<ID>

Source§

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

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

impl<ID: Eq> Eq for ExplicitQuorumSet<ID>

Source§

impl<ID: PartialEq> PartialEq for ExplicitQuorumSet<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<ExplicitQuorumSet<ID>> for ExplicitQuorumSet<ID>
where ID: Ord + Clone,

Exact quorum intersection for two lists of minimal quorums.

Every quorum of a rule holds one of its listed quorums, and every listed quorum is a quorum. Two quorums are therefore disjoint only when two listed quorums are, so the check is exact. It runs in O(a * b * n) for a and b listed quorums of at most n IDs.

Source§

fn intersects_with(&self, other: &ExplicitQuorumSet<ID>) -> Option<bool>

Return Some(false) when a listed quorum of self and one of other are disjoint, and Some(true) otherwise. This check never returns None.

A rule with no listed quorum has no quorum, so it has quorum intersection with every rule.

Source§

impl<ID> QuorumSet for ExplicitQuorumSet<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 ExplicitQuorumSet<ID>

Auto Trait Implementations§

§

impl<ID> Forget for ExplicitQuorumSet<ID>

§

impl<ID> Freeze for ExplicitQuorumSet<ID>
where Vec<BTreeSet<ID>>: Freeze,

§

impl<ID> RefUnwindSafe for ExplicitQuorumSet<ID>

§

impl<ID> Send for ExplicitQuorumSet<ID>
where Vec<BTreeSet<ID>>: Send,

§

impl<ID> Sync for ExplicitQuorumSet<ID>
where Vec<BTreeSet<ID>>: Sync,

§

impl<ID> Unpin for ExplicitQuorumSet<ID>
where Vec<BTreeSet<ID>>: Unpin,

§

impl<ID> UnsafeUnpin for ExplicitQuorumSet<ID>
where Vec<BTreeSet<ID>>: UnsafeUnpin,

§

impl<ID> UnwindSafe for ExplicitQuorumSet<ID>
where Vec<BTreeSet<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.