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>
impl<ID> ExplicitQuorumSet<ID>
Sourcepub fn new<I>(quorums: I) -> Option<Self>where
I: IntoIterator<Item = BTreeSet<ID>>,
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.
Sourcepub fn disjoint_quorums<'a>(
&'a self,
other: &'a Self,
) -> Option<(&'a BTreeSet<ID>, &'a BTreeSet<ID>)>
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>
impl<ID: Clone> Clone for ExplicitQuorumSet<ID>
Source§impl<ID: Debug> Debug for ExplicitQuorumSet<ID>
impl<ID: Debug> Debug for ExplicitQuorumSet<ID>
impl<ID: Eq> Eq for ExplicitQuorumSet<ID>
Source§impl<ID: PartialEq> PartialEq for ExplicitQuorumSet<ID>
impl<ID: PartialEq> PartialEq for ExplicitQuorumSet<ID>
Source§impl<ID> QuorumIntersection<ExplicitQuorumSet<ID>> for ExplicitQuorumSet<ID>
Exact quorum intersection for two lists of minimal quorums.
impl<ID> QuorumIntersection<ExplicitQuorumSet<ID>> for ExplicitQuorumSet<ID>
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>
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.