pub enum Tree<T: Value> {
Leaf(Leaf<T>),
PackedLeaf(PackedLeaf<T>),
Node {
hash: RwLock<Hash256>,
left: Arc<Self>,
right: Arc<Self>,
},
Zero(usize),
}Variants§
Implementations§
Source§impl<T: Value> Tree<T>
impl<T: Value> Tree<T>
pub fn empty(depth: usize) -> Arc<Self>
pub fn node(left: Arc<Self>, right: Arc<Self>, hash: Hash256) -> Arc<Self>
pub fn zero(depth: usize) -> Arc<Self>
pub fn leaf(value: T) -> Arc<Self>
pub fn leaf_with_hash(value: T, hash: Hash256) -> Arc<Self>
pub fn node_unboxed(left: Arc<Self>, right: Arc<Self>) -> Self
pub fn zero_unboxed(depth: usize) -> Self
pub fn leaf_unboxed(value: T) -> Self
pub fn get_recursive( &self, index: usize, depth: usize, packing_depth: usize, ) -> Option<&T>
Sourcepub fn with_updated_leaf(
&self,
index: usize,
new_value: T,
depth: usize,
) -> Result<Arc<Self>, Error>
pub fn with_updated_leaf( &self, index: usize, new_value: T, depth: usize, ) -> Result<Arc<Self>, Error>
Create a new tree where the indexth leaf is set to new_value.
NOTE: callers are responsible for bounds-checking index before calling this function.
pub fn with_updated_leaves<U: UpdateMap<T>>( &self, updates: &U, prefix: usize, depth: usize, hashes: Option<&BTreeMap<(usize, usize), Hash256>>, ) -> Result<Arc<Self>, Error>
Sourcepub fn compute_len(&self) -> usize
pub fn compute_len(&self) -> usize
Compute the number of elements stored in this subtree.
This method should be avoided if possible. Prefer to read the length cached in a List or
similar.
Source§impl<T: Value> Tree<T>
impl<T: Value> Tree<T>
pub fn rebase_on<'a>( orig: &'a Arc<Self>, base: &'a Arc<Self>, lengths: Option<(Length, Length)>, full_depth: usize, ) -> Result<RebaseAction<'a, Self>, Error>
Sourcepub fn intra_rebase(
orig: &Arc<Self>,
known_subtrees: &mut HashMap<(usize, Hash256), Arc<Self>>,
current_depth: usize,
) -> Result<IntraRebaseAction<Self>, Error>
pub fn intra_rebase( orig: &Arc<Self>, known_subtrees: &mut HashMap<(usize, Hash256), Arc<Self>>, current_depth: usize, ) -> Result<IntraRebaseAction<Self>, Error>
Exploit structural sharing between identical parts of the tree.
This method traverses a fully-hashed tree and replaces identical subtrees with clones of the first equal subtree. The result is a tree that shares memory for common subtrees, and thus uses less memory overall.
You MUST pass a fully-hashed tree to this function, or an Error::IntraRebaseZeroHash
error will be returned.
Arguments are:
orig: The tree to rebase.known_subtrees: map from(depth, tree_hash_root)toArc<Node>. This should be empty for the top-level call. The recursive calls fill it in. It can be discarded after the method returns.current_depth: The depth of the treeorig. This will be decremented as we recurse down the tree towards the leaves.
Presently leaves are left untouched by this procedure, so it will only produce savings in trees with equal internal nodes (i.e. equal subtrees with at least two leaves/packed leaves under them).
The input tree must be fully-hashed, and the result will also remain fully-hashed.
Trait Implementations§
Source§impl<T: Value + MemorySize> MemorySize for Tree<T>
impl<T: Value + MemorySize> MemorySize for Tree<T>
Source§fn self_pointer(&self) -> usize
fn self_pointer(&self) -> usize
Source§fn subtrees(&self) -> Vec<&dyn MemorySize>
fn subtrees(&self) -> Vec<&dyn MemorySize>
Source§fn intrinsic_size(&self) -> usize
fn intrinsic_size(&self) -> usize
Auto Trait Implementations§
impl<T> !Freeze for Tree<T>
impl<T> !RefUnwindSafe for Tree<T>
impl<T> Send for Tree<T>
impl<T> Sync for Tree<T>
impl<T> Unpin for Tree<T>where
T: Unpin,
impl<T> !UnwindSafe for Tree<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more