Skip to content

Commit

Permalink
communicate the cost in the name (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian authored Jan 12, 2024
1 parent 9ab9c74 commit f82f570
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions benches/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn chunks(n_chunks: u16, pov: &[u8]) -> Vec<Vec<u8>> {

fn erasure_root(n_chunks: u16, pov: &[u8]) -> ErasureRoot {
let chunks = chunks(n_chunks, pov);
MerklizedChunks::from(chunks).root()
MerklizedChunks::compute(chunks).root()
}

fn bench_all(c: &mut Criterion) {
Expand Down Expand Up @@ -82,7 +82,7 @@ fn bench_all(c: &mut Criterion) {
group.throughput(Throughput::Bytes(pov.len() as u64));
group.bench_with_input(BenchmarkId::from_parameter(pov_size), &N_CHUNKS, |b, _| {
b.iter(|| {
let iter = MerklizedChunks::from(all_chunks.clone());
let iter = MerklizedChunks::compute(all_chunks.clone());
let n = iter.collect::<Vec<_>>().len();
assert_eq!(n, all_chunks.len());
});
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/merklize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fuzz_target!(|data: (Vec<u8>, u16)| {
let chunks = construct_chunks(n_chunks, &data).unwrap();
assert_eq!(chunks.len() as u16, n_chunks);

let iter = MerklizedChunks::from(chunks.clone());
let iter = MerklizedChunks::compute(chunks.clone());
let root = iter.root();
let erasure_chunks: Vec<_> = iter.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mod tests {
let chunks = construct_chunks(n_chunks, &data.0).unwrap();
assert_eq!(chunks.len() as u16, n_chunks);

let iter = MerklizedChunks::from(chunks.clone());
let iter = MerklizedChunks::compute(chunks.clone());
let root = iter.root();
let erasure_chunks: Vec<_> = iter.collect();

Expand Down
9 changes: 5 additions & 4 deletions src/merklize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ impl Iterator for MerklizedChunks {
}
}

impl From<Vec<Vec<u8>>> for MerklizedChunks {
fn from(chunks: Vec<Vec<u8>>) -> Self {
impl MerklizedChunks {
/// Compute `MerklizedChunks` from a list of erasure chunks.
pub fn compute(chunks: Vec<Vec<u8>>) -> Self {
let mut hashes: Vec<Hash> = chunks
.iter()
.map(|chunk| {
Expand Down Expand Up @@ -207,7 +208,7 @@ mod tests {
#[test]
fn zero_chunks_works() {
let chunks = vec![];
let iter = MerklizedChunks::from(chunks.clone());
let iter = MerklizedChunks::compute(chunks.clone());
let root = iter.root();
let erasure_chunks: Vec<ErasureChunk> = iter.collect();
assert_eq!(erasure_chunks.len(), chunks.len());
Expand All @@ -217,7 +218,7 @@ mod tests {
#[test]
fn iter_works() {
let chunks = vec![vec![1], vec![2], vec![3]];
let iter = MerklizedChunks::from(chunks.clone());
let iter = MerklizedChunks::compute(chunks.clone());
let root = iter.root();
let erasure_chunks: Vec<ErasureChunk> = iter.collect();
assert_eq!(erasure_chunks.len(), chunks.len());
Expand Down

0 comments on commit f82f570

Please sign in to comment.