pub struct TreeNode {
pub kind: NodeKind,
pub value: Option<CompactString>,
pub children: Vec<Box<TreeNode>>,
pub id: u32,
pub subtree_size: u32,
}Fields§
§kind: NodeKind§value: Option<CompactString>§children: Vec<Box<TreeNode>>§id: u32§subtree_size: u32Implementations§
Source§impl TreeNode
impl TreeNode
Sourcepub fn leaf(kind: NodeKind, value: Option<CompactString>) -> Self
pub fn leaf(kind: NodeKind, value: Option<CompactString>) -> Self
子なしリーフを作る。id と subtree_size は finalize で確定する。
Sourcepub fn branch(kind: NodeKind, children: Vec<TreeNode>) -> Self
pub fn branch(kind: NodeKind, children: Vec<TreeNode>) -> Self
子を持つノードを作る。id と subtree_size は finalize で確定する。
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
preorder traversal で id を採番し、bottom-up で subtree_size を確定する。
構築完了後に 1 度だけ呼ぶ。
Sourcepub fn canonical_hash(&self) -> [u8; 32]
pub fn canonical_hash(&self) -> [u8; 32]
blake3(canonical bytes) を返す。
フォーマット: kind(u32 LE) | value 長(u32 LE) | value bytes | children 数(u32 LE) | 子を再帰
id / subtree_size は入力に含めない (構築順で変動するため)。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TreeNode
impl RefUnwindSafe for TreeNode
impl Send for TreeNode
impl Sync for TreeNode
impl Unpin for TreeNode
impl UnsafeUnpin for TreeNode
impl UnwindSafe for TreeNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more