Skip to content

Commit

Permalink
Merge pull request #79 from krobelus/issue-77
Browse files Browse the repository at this point in the history
RRB tree: use size table after pushing a sparse node to the left
  • Loading branch information
bodil authored Apr 8, 2019
2 parents 1b19e53 + 617c782 commit 350f5ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nodes/rrb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@ impl<A: Clone> Node<A> {
// more space in existing chunks. To keep the middle dense, we
// do not add it here.
if !chunk.is_empty() {
if side == Left && chunk.len() < NODE_SIZE {
if let Entry::Nodes(ref mut size, _) = self.children {
if let Size::Size(value) = *size {
*size = Size::table_from_size(level, value);
}
}
}
self.push_size(side, chunk.len());
self.push_child_node(side, Ref::new(Node::from_chunk(0, chunk)));
}
Expand Down
14 changes: 14 additions & 0 deletions src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2616,6 +2616,20 @@ mod test {
}
}

#[test]
fn issue_77() {
let mut x = Vector::new();
for _ in 0..44 { x.push_back(0); }
for _ in 0..20 { x.insert(0, 0); }
x.insert(1, 0);
for _ in 0..441 { x.push_back(0); }
for _ in 0..58 { x.insert(0, 0); }
x.insert(514, 0);
for _ in 0..73 { x.push_back(0); }
for _ in 0..10 { x.insert(0, 0); }
x.insert(514, 0);
}

proptest! {
#[test]
fn iter(ref vec in vec(i32::ANY, 0..1000)) {
Expand Down

0 comments on commit 350f5ac

Please sign in to comment.