Skip to content

Commit

Permalink
fix(core): fix split_off operation for RrbVec
Browse files Browse the repository at this point in the history
  • Loading branch information
arazabishov committed Oct 21, 2023
1 parent 85522ae commit eca7d94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ impl<T: Clone + Debug> RrbVec<T> {

right.tail = new_tail;
right.tail_len = new_tail_len;

// in case if tail is exactly BRANCH_FACTOR long, we should push it to the tree
right.push_tail()
} else if right.tree.len() < BRANCH_FACTOR {
// root is leaf, but it is not fully dense
// hence, some of the values should be redistributed to the actual leaf
Expand Down
15 changes: 15 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ macro_rules! make_tests {
}
}

#[test]
fn interleaving_push_split_off_push_operations() {
let mut vec_one = $vec::new();

for i in 0..(BRANCH_FACTOR * BRANCH_FACTOR) {
vec_one.push(i);
}

let mut vec_two = vec_one.split_off(BRANCH_FACTOR * BRANCH_FACTOR - BRANCH_FACTOR);
vec_two.push(0xbeef);

assert_eq!(vec_one.len(), BRANCH_FACTOR * BRANCH_FACTOR - BRANCH_FACTOR);
assert_eq!(vec_two.len(), BRANCH_FACTOR + 1);
}

#[test]
fn interleaving_different_operations_must_maintain_correct_internal_state_for_var_sizes_4() {
interleaving_different_operations_must_maintain_correct_internal_state(4);
Expand Down

0 comments on commit eca7d94

Please sign in to comment.