Rename OffsetHandler -> BTreeOverlay
This commit is contained in:
parent
ab78a15313
commit
7132ee59c0
@ -14,7 +14,7 @@ const MERKLE_HASH_CHUNCK: usize = 2 * BYTES_PER_CHUNK;
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ShouldNotProduceOffsetHandler,
|
ShouldNotProduceBTreeOverlay,
|
||||||
NoFirstNode,
|
NoFirstNode,
|
||||||
NoBytesForRoot,
|
NoBytesForRoot,
|
||||||
UnableToObtainSlices,
|
UnableToObtainSlices,
|
||||||
@ -92,7 +92,7 @@ impl TreeHashCache {
|
|||||||
where
|
where
|
||||||
T: CachedTreeHash<T>,
|
T: CachedTreeHash<T>,
|
||||||
{
|
{
|
||||||
let offset_handler = OffsetHandler::new(item, 0)?;
|
let offset_handler = BTreeOverlay::new(item, 0)?;
|
||||||
|
|
||||||
// Note how many leaves were provided. If is not a power-of-two, we'll need to pad it out
|
// Note how many leaves were provided. If is not a power-of-two, we'll need to pad it out
|
||||||
// later.
|
// later.
|
||||||
@ -263,7 +263,7 @@ fn node_range_to_byte_range(node_range: &Range<usize>) -> Range<usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct OffsetHandler {
|
pub struct BTreeOverlay {
|
||||||
num_internal_nodes: usize,
|
num_internal_nodes: usize,
|
||||||
pub num_leaf_nodes: usize,
|
pub num_leaf_nodes: usize,
|
||||||
first_node: usize,
|
first_node: usize,
|
||||||
@ -271,7 +271,7 @@ pub struct OffsetHandler {
|
|||||||
offsets: Vec<usize>,
|
offsets: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OffsetHandler {
|
impl BTreeOverlay {
|
||||||
pub fn new<T>(item: &T, initial_offset: usize) -> Result<Self, Error>
|
pub fn new<T>(item: &T, initial_offset: usize) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
T: CachedTreeHash<T>,
|
T: CachedTreeHash<T>,
|
||||||
|
@ -19,7 +19,7 @@ impl CachedTreeHash<u64> for u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn offsets(&self) -> Result<Vec<usize>, Error> {
|
fn offsets(&self) -> Result<Vec<usize>, Error> {
|
||||||
Err(Error::ShouldNotProduceOffsetHandler)
|
Err(Error::ShouldNotProduceBTreeOverlay)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn num_child_nodes(&self) -> usize {
|
fn num_child_nodes(&self) -> usize {
|
||||||
@ -78,7 +78,7 @@ where
|
|||||||
let mut offsets = vec![];
|
let mut offsets = vec![];
|
||||||
|
|
||||||
for item in self {
|
for item in self {
|
||||||
offsets.push(OffsetHandler::new(item, 0)?.total_nodes())
|
offsets.push(BTreeOverlay::new(item, 0)?.total_nodes())
|
||||||
}
|
}
|
||||||
|
|
||||||
offsets
|
offsets
|
||||||
@ -111,11 +111,11 @@ where
|
|||||||
cache: &mut TreeHashCache,
|
cache: &mut TreeHashCache,
|
||||||
chunk: usize,
|
chunk: usize,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let offset_handler = OffsetHandler::new(self, chunk)?;
|
let offset_handler = BTreeOverlay::new(self, chunk)?;
|
||||||
let old_offset_handler = OffsetHandler::new(other, chunk)?;
|
let old_offset_handler = BTreeOverlay::new(other, chunk)?;
|
||||||
|
|
||||||
if offset_handler.num_leaf_nodes != old_offset_handler.num_leaf_nodes {
|
if offset_handler.num_leaf_nodes != old_offset_handler.num_leaf_nodes {
|
||||||
let old_offset_handler = OffsetHandler::new(other, chunk)?;
|
let old_offset_handler = BTreeOverlay::new(other, chunk)?;
|
||||||
|
|
||||||
// Get slices of the exsiting tree from the cache.
|
// Get slices of the exsiting tree from the cache.
|
||||||
let (old_bytes, old_flags) = cache
|
let (old_bytes, old_flags) = cache
|
||||||
@ -180,7 +180,7 @@ where
|
|||||||
(Some(old), None) => {
|
(Some(old), None) => {
|
||||||
// Splice out the entire tree of the removed node, replacing it with a
|
// Splice out the entire tree of the removed node, replacing it with a
|
||||||
// single padding node.
|
// single padding node.
|
||||||
let end_chunk = OffsetHandler::new(old, start_chunk)?.next_node();
|
let end_chunk = BTreeOverlay::new(old, start_chunk)?.next_node();
|
||||||
|
|
||||||
cache.splice(
|
cache.splice(
|
||||||
start_chunk..end_chunk,
|
start_chunk..end_chunk,
|
||||||
|
@ -77,7 +77,7 @@ impl CachedTreeHash<Inner> for Inner {
|
|||||||
cache: &mut TreeHashCache,
|
cache: &mut TreeHashCache,
|
||||||
chunk: usize,
|
chunk: usize,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let offset_handler = OffsetHandler::new(self, chunk)?;
|
let offset_handler = BTreeOverlay::new(self, chunk)?;
|
||||||
|
|
||||||
// Skip past the internal nodes and update any changed leaf nodes.
|
// Skip past the internal nodes and update any changed leaf nodes.
|
||||||
{
|
{
|
||||||
@ -166,7 +166,7 @@ impl CachedTreeHash<Outer> for Outer {
|
|||||||
cache: &mut TreeHashCache,
|
cache: &mut TreeHashCache,
|
||||||
chunk: usize,
|
chunk: usize,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let offset_handler = OffsetHandler::new(self, chunk)?;
|
let offset_handler = BTreeOverlay::new(self, chunk)?;
|
||||||
|
|
||||||
// Skip past the internal nodes and update any changed leaf nodes.
|
// Skip past the internal nodes and update any changed leaf nodes.
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user