mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Sum tree: n_children -> n_leaves (more explicit)
This commit is contained in:
parent
20e3382785
commit
a6047903d2
1 changed files with 8 additions and 6 deletions
|
@ -116,7 +116,7 @@ impl<T: Summable> NodeData<T> {
|
||||||
(self.hash, self.sum())
|
(self.hash, self.sum())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn n_children(&self) -> usize {
|
fn n_leaves(&self) -> usize {
|
||||||
if self.full {
|
if self.full {
|
||||||
1 << self.depth
|
1 << self.depth
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,7 +126,7 @@ impl<T: Summable> NodeData<T> {
|
||||||
..
|
..
|
||||||
} = self.node
|
} = self.node
|
||||||
{
|
{
|
||||||
lchild.n_children() + rchild.n_children()
|
lchild.n_leaves() + rchild.n_leaves()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
@ -216,16 +216,18 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accessor for number of elements in the tree, not including pruned ones
|
/// Accessor for number of elements (leaves) in the tree, not including
|
||||||
|
/// pruned ones.
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.index.len()
|
self.index.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accessor for number of elements in the tree, including pruned ones
|
/// Accessor for number of elements (leaves) in the tree, including pruned
|
||||||
|
/// ones.
|
||||||
pub fn unpruned_len(&self) -> usize {
|
pub fn unpruned_len(&self) -> usize {
|
||||||
match self.root {
|
match self.root {
|
||||||
None => 0,
|
None => 0,
|
||||||
Some(ref node) => node.n_children(),
|
Some(ref node) => node.n_leaves(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +268,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
// Put new root in place and record insertion
|
// Put new root in place and record insertion
|
||||||
let index = old_root.n_children();
|
let index = old_root.n_leaves();
|
||||||
self.root = Some(SumTree::insert_right_of(old_root, new_node));
|
self.root = Some(SumTree::insert_right_of(old_root, new_node));
|
||||||
self.index.insert(index_hash, index);
|
self.index.insert(index_hash, index);
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in a new issue