pub struct ThresholdQuorumSet<ID> { /* private fields */ }Expand description
A quorum rule that accepts an ID set holding at least quorum_size of its IDs.
A read rule and a write rule over the same voters can share one ID set: build both from one
Arc. Two rules over the same IDs have quorum intersection exactly when the sum of their
quorum sizes exceeds the number of IDs.
§Examples
use std::collections::BTreeSet;
use std::num::NonZeroU64;
use std::sync::Arc;
use quorum_set::{QuorumIntersection, QuorumSet, ThresholdQuorumSet};
let voters = Arc::new(BTreeSet::from([1, 2, 3, 4, 5]));
let read = ThresholdQuorumSet::new(NonZeroU64::new(2).unwrap(), voters.clone());
let write = ThresholdQuorumSet::new(NonZeroU64::new(4).unwrap(), voters);
let read_accepts_two = read.is_quorum([1, 2].iter());
assert!(read_accepts_two);
let write_accepts_three = write.is_quorum([1, 2, 3].iter());
assert!(!write_accepts_three);
// 2 + 4 > 5, so every read quorum intersects every write quorum.
let intersects = read.intersects_with(&write);
assert_eq!(Some(true), intersects);
let shared = Arc::ptr_eq(read.id_set(), write.id_set());
assert!(shared);Implementations§
Source§impl<ID> ThresholdQuorumSet<ID>
impl<ID> ThresholdQuorumSet<ID>
Sourcepub fn id_set(&self) -> &Arc<BTreeSet<ID>> ⓘ
pub fn id_set(&self) -> &Arc<BTreeSet<ID>> ⓘ
Returns the shared ID set. QuorumSet::ids() yields the same IDs as an iterator.
Sourcepub fn quorum_size(&self) -> u64
pub fn quorum_size(&self) -> u64
Returns the number of IDs that an accepted set must hold.
Trait Implementations§
Source§impl<ID: Clone> Clone for ThresholdQuorumSet<ID>
impl<ID: Clone> Clone for ThresholdQuorumSet<ID>
Source§impl<ID: Debug> Debug for ThresholdQuorumSet<ID>
impl<ID: Debug> Debug for ThresholdQuorumSet<ID>
impl<ID: Eq> Eq for ThresholdQuorumSet<ID>
Source§impl<ID: PartialEq> PartialEq for ThresholdQuorumSet<ID>
impl<ID: PartialEq> PartialEq for ThresholdQuorumSet<ID>
Source§impl<ID> QuorumIntersection<ThresholdQuorumSet<ID>> for ThresholdQuorumSet<ID>
Exact quorum intersection for two threshold rules.
impl<ID> QuorumIntersection<ThresholdQuorumSet<ID>> for ThresholdQuorumSet<ID>
Exact quorum intersection for two threshold rules.
A smallest quorum of self first takes the IDs that other lacks, and then takes shared IDs
only as needed. A smallest quorum of other does the same. Two disjoint quorums exist exactly
when the shared IDs are enough for both, so the check is exact and runs in O(n).
Source§fn intersects_with(&self, other: &ThresholdQuorumSet<ID>) -> Option<bool>
fn intersects_with(&self, other: &ThresholdQuorumSet<ID>) -> Option<bool>
Return Some(true) when every quorum of self intersects every quorum of other, and
Some(false) otherwise. This check never returns None.
A rule whose quorum_size exceeds its number of IDs has no quorum, so it has quorum
intersection with every rule.