Apply suggestions from code review.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
9c0c9aa245
commit
ebbd2e3d2d
|
@ -535,7 +535,11 @@ impl<H, C, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
|
|||
impl<H: Hashable + Clone + Ord, C: Clone + Ord, const DEPTH: u8> BridgeTree<H, C, DEPTH> {
|
||||
/// Construct a new BridgeTree that will start recording changes from the state of
|
||||
/// the specified frontier.
|
||||
pub fn from_frontier(max_checkpoints: usize, frontier: NonEmptyFrontier<H>, checkpoint_id: C) -> Self {
|
||||
pub fn from_frontier(
|
||||
max_checkpoints: usize,
|
||||
frontier: NonEmptyFrontier<H>,
|
||||
checkpoint_id: C,
|
||||
) -> Self {
|
||||
let mut bridge = Self {
|
||||
prior_bridges: vec![],
|
||||
current_bridge: Some(MerkleBridge::from_parts(
|
||||
|
|
|
@ -15,7 +15,8 @@ pub enum FrontierError {
|
|||
PositionMismatch { expected_ommers: usize },
|
||||
/// An error representing that the position and/or list of ommers provided to frontier
|
||||
/// construction would result in a frontier that exceeds the maximum statically allowed depth
|
||||
/// of the tree.
|
||||
/// of the tree. `depth` is the minimum tree depth that would be required in order for that
|
||||
/// tree to contain the position in question.
|
||||
MaxDepthExceeded { depth: u8 },
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,7 @@ impl<H> NonEmptyFrontier<H> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Constructs a new frontier from its constituent parts
|
||||
/// Constructs a new frontier from its constituent parts.
|
||||
pub fn from_parts(position: Position, leaf: H, ommers: Vec<H>) -> Result<Self, FrontierError> {
|
||||
let expected_ommers = position.past_ommer_count();
|
||||
if ommers.len() == expected_ommers {
|
||||
|
@ -58,7 +59,7 @@ impl<H> NonEmptyFrontier<H> {
|
|||
self.position
|
||||
}
|
||||
|
||||
/// Returns the leaf most recently appended to the frontier
|
||||
/// Returns the leaf most recently appended to the frontier.
|
||||
pub fn leaf(&self) -> &H {
|
||||
&self.leaf
|
||||
}
|
||||
|
@ -71,8 +72,8 @@ impl<H> NonEmptyFrontier<H> {
|
|||
}
|
||||
|
||||
impl<H: Hashable + Clone> NonEmptyFrontier<H> {
|
||||
/// Append a new leaf to the frontier, and recompute recompute ommers by hashing together full
|
||||
/// subtrees until an empty ommer slot is found.
|
||||
/// Append a new leaf to the frontier, and recompute ommers by hashing together full subtrees
|
||||
/// until an empty ommer slot is found.
|
||||
pub fn append(&mut self, leaf: H) {
|
||||
let prior_position = self.position;
|
||||
let prior_leaf = self.leaf.clone();
|
||||
|
|
|
@ -289,11 +289,7 @@ impl Address {
|
|||
pub fn sibling(&self) -> Address {
|
||||
Address {
|
||||
level: self.level,
|
||||
index: if self.index & 0x1 == 0 {
|
||||
self.index + 1
|
||||
} else {
|
||||
self.index - 1
|
||||
},
|
||||
index: self.index ^ 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue