-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: BMT node buffer and table definition update (#136)
* BMT Node buffer * Refactor buffer, add buffer views * Simplify Node interface * Clippy * Remove unnecessary node clones * Add safety comments * Cosmetic * Return hash as ref * Replace Schema with constants * Update safety notes in BMT buffer * Replace Buffer with Primitive * Remove Primitive trait * Refactor primitive * Simplify * Make node members private * Use as ref
- Loading branch information
Brandon Vrooman
authored
Jan 13, 2023
1 parent
e001e55
commit 73cedea
Showing
5 changed files
with
88 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
mod hash; | ||
mod merkle_tree; | ||
mod node; | ||
mod primitive; | ||
|
||
pub(crate) use hash::empty_sum; | ||
pub(crate) use hash::{leaf_sum, node_sum}; | ||
pub(crate) use node::Node; | ||
|
||
pub use hash::empty_sum; | ||
pub use merkle_tree::MerkleTree; | ||
pub use merkle_tree::MerkleTreeError; | ||
pub use merkle_tree::{MerkleTree, MerkleTreeError}; | ||
pub use primitive::Primitive; | ||
pub mod in_memory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::{ | ||
binary::Node, | ||
common::{Bytes32, Position}, | ||
}; | ||
|
||
pub type Primitive = (u64, Bytes32); | ||
|
||
pub trait PrimitiveView { | ||
fn position(&self) -> Position; | ||
fn hash(&self) -> &Bytes32; | ||
} | ||
|
||
impl PrimitiveView for Primitive { | ||
fn position(&self) -> Position { | ||
Position::from_in_order_index(self.0) | ||
} | ||
|
||
fn hash(&self) -> &Bytes32 { | ||
&self.1 | ||
} | ||
} | ||
|
||
impl From<&Node> for Primitive { | ||
fn from(node: &Node) -> Self { | ||
(node.position().in_order_index(), *node.hash()) | ||
} | ||
} | ||
|
||
impl From<Primitive> for Node { | ||
fn from(primitive: Primitive) -> Self { | ||
let position = primitive.position(); | ||
let hash = *primitive.hash(); | ||
Node::new(position, hash) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters