pub struct TreeNode(/* private fields */);
Expand description
An u64 that defines a node in a bao tree.
You typically don’t have to use this, but it can be useful for debugging
and error handling. Hash validation errors contain a TreeNode
that allows
you to find the position where validation failed.
Implementations§
Source§impl TreeNode
impl TreeNode
Sourcepub const fn subtract_block_size(&self, n: u8) -> Self
pub const fn subtract_block_size(&self, n: u8) -> Self
Convert a node to a node in a tree with a smaller block size
E.g. a leaf node in a tree with block size 4 will become a node with level 4 in a tree with block size 0.
This works by just adding n trailing 1 bits to the node by shifting to the left.
Sourcepub const fn add_block_size(&self, n: u8) -> Option<Self>
pub const fn add_block_size(&self, n: u8) -> Option<Self>
Convert a node to a node in a tree with a larger block size
If the nodes has n trailing 1 bits, they are removed by shifting the node to the right by n bits.
If the node has less than n trailing 1 bits, the node is too small to be represented in the target tree.
Sourcepub const fn count_below(&self) -> u64
pub const fn count_below(&self) -> u64
Number of nodes below this node, excluding this node.
Sourcepub fn next_left_ancestor(&self) -> Option<Self>
pub fn next_left_ancestor(&self) -> Option<Self>
Get the next left ancestor of this node, or None if there is none.
Sourcepub fn left_child(&self) -> Option<Self>
pub fn left_child(&self) -> Option<Self>
Get the left child of this node, or None if it is a child node.
Sourcepub fn right_child(&self) -> Option<Self>
pub fn right_child(&self) -> Option<Self>
Get the right child of this node, or None if it is a child node.
Sourcepub fn parent(&self) -> Option<Self>
pub fn parent(&self) -> Option<Self>
Unrestricted parent, can only be None if we are at the top
Sourcepub fn restricted_parent(&self, len: Self) -> Option<Self>
pub fn restricted_parent(&self, len: Self) -> Option<Self>
Restricted parent, will be None if we call parent on the root
Sourcepub const fn node_range(&self) -> Range<Self>
pub const fn node_range(&self) -> Range<Self>
Get the range of nodes this node covers
Sourcepub fn chunk_range(&self) -> Range<ChunkNum>
pub fn chunk_range(&self) -> Range<ChunkNum>
Get the range of blocks this node covers
Sourcepub fn right_count(&self) -> u32
pub fn right_count(&self) -> u32
the number of times you have to go right from the root to get to this node
0 for a root node
Sourcepub const fn post_order_offset(&self) -> u64
pub const fn post_order_offset(&self) -> u64
Get the post order offset of this node
Sourcepub const fn post_order_range(&self) -> Range<u64>
pub const fn post_order_range(&self) -> Range<u64>
Get the range of post order offsets this node covers