refactor to const
This commit is contained in:
parent
a2bfdfbbed
commit
0ef99a62a4
|
@ -1680,10 +1680,6 @@ name = "yaml-rust"
|
|||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "rust-crypto"
|
||||
version = "0.2.36"
|
||||
|
||||
[metadata]
|
||||
"checksum abstract-ns 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2f451afbdf8ed8c8f8a98433055bb9a6b7a72aef4baff16227d2a43dd547f43b"
|
||||
"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699"
|
||||
|
|
|
@ -73,15 +73,13 @@ lazy_static! {
|
|||
}
|
||||
|
||||
pub trait Dim {
|
||||
fn height() -> u32;
|
||||
const HEIGHT: usize;
|
||||
}
|
||||
|
||||
pub struct H32;
|
||||
|
||||
impl Dim for H32 {
|
||||
fn height() -> u32 {
|
||||
32
|
||||
}
|
||||
const HEIGHT: usize = 32;
|
||||
}
|
||||
|
||||
pub struct TreeState<D: Dim> {
|
||||
|
@ -97,7 +95,7 @@ impl<D: Dim> TreeState<D> {
|
|||
_phantom: ::std::marker::PhantomData,
|
||||
left: None,
|
||||
right: None,
|
||||
parents: vec![None; D::height() as usize - 1],
|
||||
parents: vec![None; D::HEIGHT - 1],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +111,7 @@ impl<D: Dim> TreeState<D> {
|
|||
.expect("none variant is handled in the branch above; qed");
|
||||
|
||||
let mut combined = sha256_compress(&*former_left, &*former_right);
|
||||
for i in 0..D::height()-1 {
|
||||
for i in 0..D::HEIGHT-1 {
|
||||
let parent_slot = self.parents.get_mut(i as usize)
|
||||
.expect("Vector is at least self.height in size");
|
||||
|
||||
|
@ -137,7 +135,7 @@ impl<D: Dim> TreeState<D> {
|
|||
|
||||
let mut root = sha256_compress(&**left, &**right);
|
||||
|
||||
for i in 0..D::height()-1 {
|
||||
for i in 0..D::HEIGHT-1 {
|
||||
match &self.parents[i as usize] {
|
||||
&Some(ref parent) => { root = sha256_compress(&**parent, &*root); }
|
||||
&None => { root = sha256_compress(&*root, &*EMPTY_ROOTS[i as usize + 1]); },
|
||||
|
@ -179,9 +177,7 @@ mod tests {
|
|||
pub struct H4;
|
||||
|
||||
impl Dim for H4 {
|
||||
fn height() -> u32 {
|
||||
4
|
||||
}
|
||||
const HEIGHT: usize = 4;
|
||||
}
|
||||
|
||||
type TestTreeState = TreeState<H4>;
|
||||
|
@ -189,17 +185,13 @@ mod tests {
|
|||
pub struct H1;
|
||||
|
||||
impl Dim for H1 {
|
||||
fn height() -> u32 {
|
||||
1
|
||||
}
|
||||
const HEIGHT: usize = 1;
|
||||
}
|
||||
|
||||
pub struct H2;
|
||||
|
||||
impl Dim for H2 {
|
||||
fn height() -> u32 {
|
||||
2
|
||||
}
|
||||
const HEIGHT: usize = 2;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue