Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

CMTNodeTrait

Fully qualified path: cartesian_merkle_tree::library::node::CMTNodeTrait

pub trait CMTNodeTrait

Trait 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 node
  • priority - 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::CMTNodeTrait::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 node
  • priority - The priority value for heap ordering
  • left_child - Optional left child node
  • right_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::CMTNodeTrait::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::CMTNodeTrait::update_merkle_hash

fn update_merkle_hash(ref self: CMTNode)