set_at_index sets the default value (0) if index doesn't exist in the other vector

This commit is contained in:
Andy Wang 2022-04-15 21:44:22 +01:00
parent e7698f4f07
commit aca3b3a645
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374

View File

@ -108,10 +108,8 @@ pub fn join(&mut self, other: &Self) {
/// Set the element at the current index of the vector
pub fn set_at_index(&mut self, other: &Self, idx: VectorIdx) {
let idx = idx.index();
let mut_slice = self.get_mut_with_min_len(idx + 1);
let slice = other.as_slice();
mut_slice[idx] = slice[idx];
let mut_slice = self.get_mut_with_min_len(idx.index() + 1);
mut_slice[idx.index()] = other[idx];
}
/// Set the vector to the all-zero vector