Struct diem_types::proof::position::Position
source · pub struct Position(_);
Implementations§
source§impl Position
impl Position
sourcepub fn level(self) -> u32
pub fn level(self) -> u32
What level is this node in the tree, 0 if the node is a leaf, 1 if the level is one above a leaf, etc.
pub fn is_leaf(self) -> bool
sourcepub fn from_level_and_pos(level: u32, pos: u64) -> Self
pub fn from_level_and_pos(level: u32, pos: u64) -> Self
pos count start from 0 on each level
pub fn from_inorder_index(index: u64) -> Self
pub fn to_inorder_index(self) -> u64
pub fn from_postorder_index(index: u64) -> Result<Self>
pub fn to_postorder_index(self) -> u64
sourcepub fn left_child(self) -> Self
pub fn left_child(self) -> Self
What is the left node of this node? Will overflow if the node is a leaf
sourcepub fn right_child(self) -> Self
pub fn right_child(self) -> Self
What is the right node of this node? Will overflow if the node is a leaf
sourcepub fn is_left_child(self) -> bool
pub fn is_left_child(self) -> bool
Whether this position is a left child of its parent. The observation is that, after stripping out all right-most 1 bits, a left child will have a bit pattern of xxx00(11..), while a right child will be represented by xxx10(11..)
pub fn is_right_child(self) -> bool
pub fn from_leaf_index(leaf_index: u64) -> Self
sourcepub fn sibling(self) -> Self
pub fn sibling(self) -> Self
This method takes in a node position and return its sibling position
The observation is that, after stripping out the right-most common bits, two sibling nodes flip the the next right-most bits with each other. To find out the right-most common bits, first remove all the right-most ones because they are corresponding to level’s indicator. Then remove next zero right after.
sourcepub fn root_from_leaf_index(leaf_index: u64) -> Self
pub fn root_from_leaf_index(leaf_index: u64) -> Self
This method calculates the index of the smallest root which contains this leaf. Observe that, the root position is composed by a “height” number of ones
For example
0010010(node)
0011111(smearing)
-------
0001111(root)
pub fn root_from_leaf_count(leaf_count: LeafCount) -> Self
pub fn root_level_from_leaf_count(leaf_count: LeafCount) -> u32
sourcepub fn right_most_child(self) -> Self
pub fn right_most_child(self) -> Self
Given a node, find its right most child in its subtree. Right most child is a Position, could be itself, at level 0
sourcepub fn left_most_child(self) -> Self
pub fn left_most_child(self) -> Self
Given a node, find its left most child in its subtree Left most child is a node, could be itself, at level 0
source§impl Position
impl Position
pub fn is_freezable(self, leaf_index: u64) -> bool
pub fn is_placeholder(self, leaf_index: u64) -> bool
sourcepub fn iter_ancestor(self) -> AncestorIterator ⓘ
pub fn iter_ancestor(self) -> AncestorIterator ⓘ
Creates an AncestorIterator
using this position.
sourcepub fn iter_ancestor_sibling(self) -> AncestorSiblingIterator ⓘ
pub fn iter_ancestor_sibling(self) -> AncestorSiblingIterator ⓘ
Creates an AncestorSiblingIterator
using this position.
Trait Implementations§
source§impl Ord for Position
impl Ord for Position
source§impl PartialEq<Position> for Position
impl PartialEq<Position> for Position
source§impl PartialOrd<Position> for Position
impl PartialOrd<Position> for Position
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 moreimpl Copy for Position
impl Eq for Position
impl StructuralEq for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.