Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RRB tree: use size table after pushing a sparse node to the left #79

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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