CMTNodeImpl
Fully qualified path: cartesian_merkle_tree::library::node::CMTNodeImpl
pub impl CMTNodeImpl of CMTNodeTrait;
Impl functions
new
Creates a new CMT node with the specified key and priority.
The node is initialized with no children and a zero Merkle hash.
The hash should be updated using update_merkle_hash() after creation.
Arguments
key- The key value for this nodepriority- The priority value for heap ordering
Returns
A new CMTNode with the specified key and priority
Examples
let key = 42;
let priority = CMTUtilsTrait::calculate_priority(key);
let node = CMTNodeTrait::new(key, priority);
assert_eq!(node.key, key);
assert_eq!(node.merkle_hash, 0);
Fully qualified path: cartesian_merkle_tree::library::node::CMTNodeImpl::new
fn new(key: felt252, priority: felt252) -> CMTNode
new_with_children
Creates a new CMT node with the specified key, priority, and children.
The Merkle hash is automatically calculated based on the key and children hashes. This is typically used during tree rotations or reconstruction.
Arguments
key- The key value for this nodepriority- The priority value for heap orderingleft_child- Optional left child noderight_child- Optional right child node
Returns
A new CMTNode with calculated Merkle hash
Examples
let node = CMTNodeTrait::new_with_children(
50, priority, Some(left_box), Some(right_box)
);
assert!(node.merkle_hash != 0);
Fully qualified path: cartesian_merkle_tree::library::node::CMTNodeImpl::new_with_children
fn new_with_children(
key: felt252,
priority: felt252,
left_child: Option<Box<CMTNode>>,
right_child: Option<Box<CMTNode>>,
) -> CMTNode
update_merkle_hash
Updates the Merkle hash of this node based on its key and current children.
This method should be called whenever the node’s children change to maintain the cryptographic integrity of the tree. The hash is computed deterministically using the node’s key and its children’s hashes.
Examples
let mut node = CMTNodeTrait::new(key, priority);
node.left_child = Some(left_child_box);
node.update_merkle_hash(); // Hash now reflects the new child
Fully qualified path: cartesian_merkle_tree::library::node::CMTNodeImpl::update_merkle_hash
fn update_merkle_hash(ref self: CMTNode)