lighthouse-pulse/eth2/utils/cached_tree_hash/src/impls.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

use super::*;
2019-04-25 23:55:03 +00:00
use crate::merkleize::merkleize;
pub mod vec;
2019-04-15 02:01:12 +00:00
impl CachedTreeHash<u64> for u64 {
2019-04-24 08:13:37 +00:00
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
2019-04-13 03:18:18 +00:00
Ok(TreeHashCache::from_bytes(
2019-04-17 01:18:00 +00:00
merkleize(self.to_le_bytes().to_vec()),
2019-04-13 03:18:18 +00:00
false,
2019-04-23 23:29:32 +00:00
None,
2019-04-13 03:18:18 +00:00
)?)
}
2019-04-24 08:13:37 +00:00
fn num_tree_hash_cache_chunks(&self) -> usize {
1
}
2019-04-26 01:34:07 +00:00
fn tree_hash_cache_overlay(&self, _chunk_offset: usize, _depth: usize) -> BTreeOverlay {
unreachable!("Basic should not produce overlay");
2019-04-24 08:13:37 +00:00
}
fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> {
let leaf = merkleize(self.to_le_bytes().to_vec());
cache.maybe_update_chunk(cache.chunk_index, &leaf)?;
cache.chunk_index += 1;
// cache.overlay_index += 1;
Ok(())
}
}
impl CachedTreeHash<usize> for usize {
2019-04-24 08:13:37 +00:00
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
Ok(TreeHashCache::from_bytes(
merkleize(self.to_le_bytes().to_vec()),
false,
None,
)?)
}
fn num_tree_hash_cache_chunks(&self) -> usize {
1
}
2019-04-26 01:34:07 +00:00
fn tree_hash_cache_overlay(&self, _chunk_offset: usize, _depth: usize) -> BTreeOverlay {
unreachable!("Basic should not produce overlay");
}
fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> {
let leaf = merkleize(self.to_le_bytes().to_vec());
cache.maybe_update_chunk(cache.chunk_index, &leaf)?;
cache.chunk_index += 1;
2019-04-23 23:29:32 +00:00
// cache.overlay_index += 1;
2019-04-22 11:31:39 +00:00
Ok(())
}
}