Remove child_nodes method from CachedTreeHash

This commit is contained in:
Paul Hauner 2019-04-15 11:44:44 +10:00
parent c87a0fc588
commit e6c33e1b60
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
3 changed files with 9 additions and 44 deletions

View File

@ -14,18 +14,14 @@ impl CachedTreeHash<u64> for u64 {
)?)
}
fn btree_overlay(&self, _chunk_offset: usize) -> Result<BTreeOverlay, Error> {
Err(Error::ShouldNotProduceBTreeOverlay)
fn btree_overlay(&self, chunk_offset: usize) -> Result<BTreeOverlay, Error> {
BTreeOverlay::from_lengths(chunk_offset, vec![1])
}
fn num_bytes(&self) -> usize {
8
}
fn num_child_nodes(&self) -> usize {
0
}
fn packed_encoding(&self) -> Vec<u8> {
ssz_encode(self)
}
@ -72,7 +68,6 @@ where
}
fn btree_overlay(&self, chunk_offset: usize) -> Result<BTreeOverlay, Error> {
//
let lengths = match T::item_type() {
ItemType::Basic => vec![1; self.len() / T::packing_factor()],
ItemType::Composite | ItemType::List => {
@ -89,11 +84,6 @@ where
BTreeOverlay::from_lengths(chunk_offset, lengths)
}
fn num_child_nodes(&self) -> usize {
// TODO
42
}
fn num_bytes(&self) -> usize {
self.iter().fold(0, |acc, item| acc + item.num_bytes())
}

View File

@ -47,8 +47,6 @@ pub trait CachedTreeHash<Item>: Debug {
fn btree_overlay(&self, chunk_offset: usize) -> Result<BTreeOverlay, Error>;
fn num_child_nodes(&self) -> usize;
fn packed_encoding(&self) -> Vec<u8>;
fn packing_factor() -> usize;

View File

@ -47,26 +47,14 @@ impl CachedTreeHash<Inner> for Inner {
fn btree_overlay(&self, chunk_offset: usize) -> Result<BTreeOverlay, Error> {
let mut lengths = vec![];
lengths.push(self.a.num_child_nodes() + 1);
lengths.push(self.b.num_child_nodes() + 1);
lengths.push(self.c.num_child_nodes() + 1);
lengths.push(self.d.num_child_nodes() + 1);
lengths.push(BTreeOverlay::new(&self.a, 0)?.total_nodes());
lengths.push(BTreeOverlay::new(&self.b, 0)?.total_nodes());
lengths.push(BTreeOverlay::new(&self.c, 0)?.total_nodes());
lengths.push(BTreeOverlay::new(&self.d, 0)?.total_nodes());
BTreeOverlay::from_lengths(chunk_offset, lengths)
}
fn num_child_nodes(&self) -> usize {
let mut children = 0;
let leaves = 4;
children += self.a.num_child_nodes();
children += self.b.num_child_nodes();
children += self.c.num_child_nodes();
children += self.d.num_child_nodes();
num_nodes(leaves) + children - 1
}
fn packed_encoding(&self) -> Vec<u8> {
panic!("Struct should never be packed")
}
@ -135,23 +123,12 @@ impl CachedTreeHash<Outer> for Outer {
bytes
}
fn num_child_nodes(&self) -> usize {
let mut children = 0;
let leaves = 3;
children += self.a.num_child_nodes();
children += self.b.num_child_nodes();
children += self.c.num_child_nodes();
num_nodes(leaves) + children - 1
}
fn btree_overlay(&self, chunk_offset: usize) -> Result<BTreeOverlay, Error> {
let mut lengths = vec![];
lengths.push(self.a.num_child_nodes() + 1);
lengths.push(self.b.num_child_nodes() + 1);
lengths.push(self.c.num_child_nodes() + 1);
lengths.push(BTreeOverlay::new(&self.a, 0)?.total_nodes());
lengths.push(BTreeOverlay::new(&self.b, 0)?.total_nodes());
lengths.push(BTreeOverlay::new(&self.c, 0)?.total_nodes());
BTreeOverlay::from_lengths(chunk_offset, lengths)
}