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
Trait Implementations§
source§impl Ord for TreeNode
impl Ord for TreeNode
source§impl PartialEq for TreeNode
impl PartialEq for TreeNode
source§impl PartialOrd for TreeNode
impl PartialOrd for TreeNode
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more