pub struct QuorumTree<ID>where
ID: Ord,{ /* private fields */ }Expand description
A single quorum rule represented as a tree.
QuorumTree models one side of a quorum configuration. A consensus
implementation should usually build one tree for read quorums and another
tree for write quorums, then ensure every read quorum intersects every write
quorum.
A child node is selected when it is either an included node ID or a nested quorum tree whose own quorum rule is satisfied.
§Invariants
- A
QuorumTreerepresents exactly one quorum rule. - Child nodes are unique and traversal order is deterministic according to
Nodeordering. quorum_sizenever exceeds the number of child nodes: construction rejects duplicate children and unsatisfiable quorum sizes.- Equality and ordering for
QuorumTreeare based only on its canonical ID. - Canonical IDs are stable identifiers.
std::fmt::Displayis human-readable output and is not a serialization format.
Implementations§
Source§impl<ID> QuorumTree<ID>where
ID: Ord,
impl<ID> QuorumTree<ID>where
ID: Ord,
Sourcepub fn new(
quorum_size: u64,
nodes: impl IntoIterator<Item = Node<ID>>,
) -> Result<Self, QuorumTreeError>where
ID: CanonicalId,
pub fn new(
quorum_size: u64,
nodes: impl IntoIterator<Item = Node<ID>>,
) -> Result<Self, QuorumTreeError>where
ID: CanonicalId,
Builds a quorum tree from a quorum size and child nodes.
quorum_size is the number of child nodes that must be selected for this
tree to be selected. A child can be a single ID or another quorum tree.
If quorum_size is 0, every input satisfies the tree.
§Errors
QuorumTreeError::DuplicateChild: a child was given more than once. A duplicate child is always an upstream bug; a tree never contains the same child twice.QuorumTreeError::UnsatisfiableQuorum:quorum_sizeexceeds the number of child nodes, so no input could satisfy the tree.
§Examples
use quorum_set::{Node, QuorumSet, QuorumTree, QuorumTreeError};
let tree = QuorumTree::new(2, [
Node::Id(1),
Node::Id(2),
Node::Id(3),
]).unwrap();
assert!(tree.is_quorum([1, 2].iter()));
assert!(!tree.is_quorum([1].iter()));
let err = QuorumTree::new(1, [Node::Id(1), Node::Id(1)]).unwrap_err();
assert_eq!(
QuorumTreeError::DuplicateChild { canonical_id: "Id=1".to_string() },
err
);Sourcepub fn quorum_size(&self) -> u64
pub fn quorum_size(&self) -> u64
Returns the number of selected child nodes required to satisfy this tree.
Sourcepub fn children(&self) -> impl Iterator<Item = &Node<ID>>
pub fn children(&self) -> impl Iterator<Item = &Node<ID>>
Returns this tree’s child nodes in canonical order.
Children are unique: construction rejects duplicate child nodes.
Sourcepub fn canonical_id(&self) -> &str
pub fn canonical_id(&self) -> &str
Returns the canonical ID of this tree.
The canonical ID decides equality and ordering. It is computed once at construction, so this accessor does not allocate.
Trait Implementations§
Source§impl<ID> CanonicalId for QuorumTree<ID>where
ID: Ord + CanonicalId,
impl<ID> CanonicalId for QuorumTree<ID>where
ID: Ord + CanonicalId,
Source§impl<ID> Clone for QuorumTree<ID>
impl<ID> Clone for QuorumTree<ID>
Source§fn clone(&self) -> QuorumTree<ID>
fn clone(&self) -> QuorumTree<ID>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<ID> Debug for QuorumTree<ID>
impl<ID> Debug for QuorumTree<ID>
Source§impl<ID> Display for QuorumTree<ID>
impl<ID> Display for QuorumTree<ID>
impl<ID> Eq for QuorumTree<ID>where
ID: Ord,
Source§impl<ID> Hash for QuorumTree<ID>where
ID: Ord,
Hashing is based solely on canonical_id, consistent with equality.
impl<ID> Hash for QuorumTree<ID>where
ID: Ord,
Hashing is based solely on canonical_id, consistent with equality.
Source§impl<ID> Ord for QuorumTree<ID>where
ID: Ord,
impl<ID> Ord for QuorumTree<ID>where
ID: Ord,
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<ID> PartialEq for QuorumTree<ID>where
ID: Ord,
Equality and ordering are decided solely by canonical_id.
impl<ID> PartialEq for QuorumTree<ID>where
ID: Ord,
Equality and ordering are decided solely by canonical_id.
new() is the sole constructor and canonical_id is the cached canonical
representation of the quorum tree spec. A single string comparison keeps
BTreeSet operations cheap; no recursive structural comparison is needed.
Source§impl<ID> PartialOrd for QuorumTree<ID>where
ID: Ord,
impl<ID> PartialOrd for QuorumTree<ID>where
ID: Ord,
Source§impl<ID> QuorumSet for QuorumTree<ID>
Hierarchical quorum implementation for QuorumTree.
impl<ID> QuorumSet for QuorumTree<ID>
Hierarchical quorum implementation for QuorumTree.
Evaluation follows the tree structure. ids() returns all leaf IDs once,
even when the same node appears in more than one subtree.