Struct bridgetree::Level
source · #[repr(transparent)]pub struct Level(_);
Expand description
A type-safe wrapper for indexing into “levels” of a binary tree, such that
nodes at level 0
are leaves, nodes at level 1
are parents of nodes at
level 0
, and so forth. This type is capable of representing levels in
trees containing up to 2^255 leaves.
Implementations§
source§impl Level
impl Level
sourcepub fn iter_to(self, other: Level) -> impl Iterator<Item = Self>
pub fn iter_to(self, other: Level) -> impl Iterator<Item = Self>
Examples found in repository?
More examples
src/lib.rs (line 199)
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
pub fn root(&self, root_level: Option<Level>) -> H {
let max_level = root_level.unwrap_or_else(|| self.position.root_level());
self.position
.witness_addrs(max_level)
.fold(
(self.leaf.clone(), Level::from(0)),
|(digest, complete_lvl), (addr, source)| {
// fold up from complete_lvl to addr.level() pairing with empty roots; if
// complete_lvl == addr.level() this is just the complete digest to this point
let digest = complete_lvl
.iter_to(addr.level())
.fold(digest, |d, l| H::combine(l, &d, &H::empty_root(l)));
let res_digest = match source {
Source::Past(i) => H::combine(addr.level(), &self.ommers[i], &digest),
Source::Future => {
H::combine(addr.level(), &digest, &H::empty_root(addr.level()))
}
};
(res_digest, addr.level() + 1)
},
)
.0
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for Level
impl<'de> Deserialize<'de> for Level
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Level
impl Ord for Level
source§impl PartialEq<Level> for Level
impl PartialEq<Level> for Level
source§impl PartialOrd<Level> for Level
impl PartialOrd<Level> for Level
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more