Skip to main content

ThresholdQuorumSet

Struct ThresholdQuorumSet 

Source
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>

Source

pub fn new(quorum_size: NonZeroU64, ids: impl Into<Arc<BTreeSet<ID>>>) -> Self

Builds a rule that accepts an ID set holding at least quorum_size of ids.

ids is a BTreeSet, or an Arc of one to share it with another rule. A quorum_size above the number of ids gives a rule that accepts no set.

Source

pub fn id_set(&self) -> &Arc<BTreeSet<ID>> ⓘ

Returns the shared ID set. QuorumSet::ids() yields the same IDs as an iterator.

Source

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>

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 ThresholdQuorumSet<ID>

Source§

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

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

impl<ID: Eq> Eq for ThresholdQuorumSet<ID>

Source§

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

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>

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.

Source§

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

Auto Trait Implementations§

§

impl<ID> Freeze for ThresholdQuorumSet<ID>
where Arc<BTreeSet<ID>>: Freeze,

§

impl<ID> RefUnwindSafe for ThresholdQuorumSet<ID>

§

impl<ID> Send for ThresholdQuorumSet<ID>
where Arc<BTreeSet<ID>>: Send,

§

impl<ID> Sync for ThresholdQuorumSet<ID>
where Arc<BTreeSet<ID>>: Sync,

§

impl<ID> Unpin for ThresholdQuorumSet<ID>
where Arc<BTreeSet<ID>>: Unpin,

§

impl<ID> UnsafeUnpin for ThresholdQuorumSet<ID>
where Arc<BTreeSet<ID>>: UnsafeUnpin,

§

impl<ID> UnwindSafe for ThresholdQuorumSet<ID>
where Arc<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.