From eca7d94322d51975970071bff0853b7474333852 Mon Sep 17 00:00:00 2001 From: Araz Abishov Date: Sat, 21 Oct 2023 22:02:51 +0200 Subject: [PATCH] fix(core): fix split_off operation for RrbVec --- src/core/mod.rs | 3 +++ tests/tests.rs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/core/mod.rs b/src/core/mod.rs index c2fdd21c0..33c3a81fc 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -345,6 +345,9 @@ impl RrbVec { 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 diff --git a/tests/tests.rs b/tests/tests.rs index 469ca6f8b..156ba21d6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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);