2019-03-28 00:11:20 +00:00
|
|
|
use super::*;
|
2019-04-25 23:55:03 +00:00
|
|
|
use crate::merkleize::merkleize;
|
2019-03-28 00:11:20 +00:00
|
|
|
|
2019-04-26 01:15:17 +00:00
|
|
|
pub mod vec;
|
2019-04-15 02:01:12 +00:00
|
|
|
|
2019-04-24 08:23:58 +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-03-28 00:11:20 +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(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 08:23:58 +00:00
|
|
|
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");
|
2019-03-28 00:11:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-21 02:12:47 +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)?;
|
2019-03-28 00:11:20 +00:00
|
|
|
|
2019-04-21 02:12:47 +00:00
|
|
|
cache.chunk_index += 1;
|
2019-04-23 23:29:32 +00:00
|
|
|
// cache.overlay_index += 1;
|
2019-04-22 11:31:39 +00:00
|
|
|
|
2019-04-21 02:12:47 +00:00
|
|
|
Ok(())
|
2019-03-28 00:11:20 +00:00
|
|
|
}
|
|
|
|
}
|