Fix failing struct vec vectors
This commit is contained in:
parent
48cf75e394
commit
d79616fee6
@ -145,30 +145,20 @@ impl TreeHashCache {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn single_chunk_splice<I>(&mut self, chunk: usize, replace_with: I) -> Splice<I::IntoIter>
|
pub fn single_chunk_splice<I>(&mut self, chunk: usize, replace_with: Vec<u8>) {
|
||||||
where
|
self.chunk_splice(chunk..chunk + 1, replace_with);
|
||||||
I: IntoIterator<Item = u8>,
|
|
||||||
{
|
|
||||||
self.chunk_splice(chunk..chunk + 1, replace_with)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chunk_splice<I>(
|
pub fn chunk_splice(&mut self, chunk_range: Range<usize>, replace_with: Vec<u8>) {
|
||||||
&mut self,
|
|
||||||
chunk_range: Range<usize>,
|
|
||||||
replace_with: I,
|
|
||||||
) -> Splice<I::IntoIter>
|
|
||||||
where
|
|
||||||
I: IntoIterator<Item = u8>,
|
|
||||||
{
|
|
||||||
let byte_start = chunk_range.start * BYTES_PER_CHUNK;
|
let byte_start = chunk_range.start * BYTES_PER_CHUNK;
|
||||||
let byte_end = chunk_range.end * BYTES_PER_CHUNK;
|
let byte_end = chunk_range.end * BYTES_PER_CHUNK;
|
||||||
|
|
||||||
// Update the `chunk_modified` vec, marking all spliced-in nodes as changed.
|
// Update the `chunk_modified` vec, marking all spliced-in nodes as changed.
|
||||||
self.chunk_modified.splice(
|
self.chunk_modified.splice(
|
||||||
chunk_range.clone(),
|
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> {
|
pub fn maybe_update_chunk(&mut self, chunk: usize, to: &[u8]) -> Result<(), Error> {
|
||||||
|
@ -153,7 +153,6 @@ where
|
|||||||
// The item didn't exist in the old list and doesn't exist in the new list,
|
// The item didn't exist in the old list and doesn't exist in the new list,
|
||||||
// nothing to do.
|
// nothing to do.
|
||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
_ => panic!("variable sized lists not implemented"),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,9 +473,14 @@ fn test_inner_vec_modifications(original: Vec<Inner>, modified: Vec<Inner>, refe
|
|||||||
full_bytes.append(&mut merkle);
|
full_bytes.append(&mut merkle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let num_leaves = leaves.len() / HASHSIZE;
|
||||||
|
|
||||||
let mut expected = merkleize(leaves);
|
let mut expected = merkleize(leaves);
|
||||||
expected.splice(3 * HASHSIZE.., full_bytes);
|
expected.splice(3 * HASHSIZE.., full_bytes);
|
||||||
|
|
||||||
|
for _ in num_leaves..num_leaves.next_power_of_two() {
|
||||||
expected.append(&mut vec![0; HASHSIZE]);
|
expected.append(&mut vec![0; HASHSIZE]);
|
||||||
|
}
|
||||||
|
|
||||||
// Compare the cached tree to the reference tree.
|
// Compare the cached tree to the reference tree.
|
||||||
assert_trees_eq(&expected, &modified_cache);
|
assert_trees_eq(&expected, &modified_cache);
|
||||||
|
Loading…
Reference in New Issue
Block a user