Fix failing struct vec vectors

This commit is contained in:
Paul Hauner 2019-04-12 16:52:11 +10:00
parent 48cf75e394
commit d79616fee6
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
3 changed files with 11 additions and 17 deletions

View File

@ -145,30 +145,20 @@ impl TreeHashCache {
})
}
pub fn single_chunk_splice<I>(&mut self, chunk: usize, replace_with: I) -> Splice<I::IntoIter>
where
I: IntoIterator<Item = u8>,
{
self.chunk_splice(chunk..chunk + 1, replace_with)
pub fn single_chunk_splice<I>(&mut self, chunk: usize, replace_with: Vec<u8>) {
self.chunk_splice(chunk..chunk + 1, replace_with);
}
pub fn chunk_splice<I>(
&mut self,
chunk_range: Range<usize>,
replace_with: I,
) -> Splice<I::IntoIter>
where
I: IntoIterator<Item = u8>,
{
pub fn chunk_splice(&mut self, chunk_range: Range<usize>, replace_with: Vec<u8>) {
let byte_start = chunk_range.start * BYTES_PER_CHUNK;
let byte_end = chunk_range.end * BYTES_PER_CHUNK;
// Update the `chunk_modified` vec, marking all spliced-in nodes as changed.
self.chunk_modified.splice(
chunk_range.clone(),
vec![true; chunk_range.end - chunk_range.start],
vec![true; replace_with.len() / HASHSIZE],
);
self.cache.splice(byte_start..byte_end, replace_with)
self.cache.splice(byte_start..byte_end, replace_with);
}
pub fn maybe_update_chunk(&mut self, chunk: usize, to: &[u8]) -> Result<(), Error> {

View File

@ -153,7 +153,6 @@ where
// The item didn't exist in the old list and doesn't exist in the new list,
// nothing to do.
(None, None) => {}
_ => panic!("variable sized lists not implemented"),
};
}
}

View File

@ -473,9 +473,14 @@ fn test_inner_vec_modifications(original: Vec<Inner>, modified: Vec<Inner>, refe
full_bytes.append(&mut merkle);
}
let num_leaves = leaves.len() / HASHSIZE;
let mut expected = merkleize(leaves);
expected.splice(3 * HASHSIZE.., full_bytes);
expected.append(&mut vec![0; HASHSIZE]);
for _ in num_leaves..num_leaves.next_power_of_two() {
expected.append(&mut vec![0; HASHSIZE]);
}
// Compare the cached tree to the reference tree.
assert_trees_eq(&expected, &modified_cache);