mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-09 15:41:30 +01:00
feat: implement get_size_hint for Smt (#331)
This commit is contained in:
committed by
GitHub
parent
c2eb38c236
commit
8adc0ab418
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1157,9 +1157,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winter-math"
|
name = "winter-math"
|
||||||
version = "0.9.0"
|
version = "0.9.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "004f85bb051ce986ec0b9a2bd90aaf81b83e3c67464becfdf7db31f14c1019ba"
|
checksum = "5b0e685b3b872d82e58a86519294a814b7bc7a4d3cd2c93570a7d80c0c5a1aba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"winter-utils",
|
"winter-utils",
|
||||||
|
|||||||
@@ -314,6 +314,14 @@ impl Serializable for Smt {
|
|||||||
target.write(value);
|
target.write(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_size_hint(&self) -> usize {
|
||||||
|
let entries_count = self.entries().count();
|
||||||
|
|
||||||
|
// Each entry is the size of a digest plus a word.
|
||||||
|
entries_count.get_size_hint()
|
||||||
|
+ entries_count * (RpoDigest::SERIALIZED_SIZE + EMPTY_WORD.get_size_hint())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deserializable for Smt {
|
impl Deserializable for Smt {
|
||||||
@@ -339,6 +347,7 @@ fn test_smt_serialization_deserialization() {
|
|||||||
let smt_default = Smt::default();
|
let smt_default = Smt::default();
|
||||||
let bytes = smt_default.to_bytes();
|
let bytes = smt_default.to_bytes();
|
||||||
assert_eq!(smt_default, Smt::read_from_bytes(&bytes).unwrap());
|
assert_eq!(smt_default, Smt::read_from_bytes(&bytes).unwrap());
|
||||||
|
assert_eq!(bytes.len(), smt_default.get_size_hint());
|
||||||
|
|
||||||
// Smt with values
|
// Smt with values
|
||||||
let smt_leaves_2: [(RpoDigest, Word); 2] = [
|
let smt_leaves_2: [(RpoDigest, Word); 2] = [
|
||||||
@@ -355,4 +364,5 @@ fn test_smt_serialization_deserialization() {
|
|||||||
|
|
||||||
let bytes = smt.to_bytes();
|
let bytes = smt.to_bytes();
|
||||||
assert_eq!(smt, Smt::read_from_bytes(&bytes).unwrap());
|
assert_eq!(smt, Smt::read_from_bytes(&bytes).unwrap());
|
||||||
|
assert_eq!(bytes.len(), smt.get_size_hint());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user