Skip to content

Update README example with new iterators #43

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

Merged
merged 3 commits into from
Mar 10, 2017
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
5 changes: 4 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ fn_brace_style = "SameLineWhere"
fn_return_indent = "WithWhereClause"
fn_args_density = "Compressed"
where_layout = "Horizontal"
format_strings = false
format_strings = false
chain_one_line_max = 15
ideal_width = 100
take_source_hints = true
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,11 @@ fn main() {
tree.insert(Node::new(3), UnderNode(&child_id)).unwrap();
tree.insert(Node::new(4), UnderNode(&child_id)).unwrap();

println!("Pre-order:");
print_pre_order(&tree, &root_id);
// results in the output "0, 1, 3, 4, 2, "
}

fn print_pre_order(tree: &Tree<i32>, node_id: &NodeId) {
let node_ref = tree.get(node_id).unwrap();

print!("{}, ", node_ref.data());

for child_id in node_ref.children() {
print_pre_order(tree, &child_id);
println!("Post-order:");
for node in tree.traverse_pre_order(&root_id).unwrap() {
print!("{}, ", node.data());
}
// results in the output "0, 1, 3, 4, 2, "
}
```

Expand Down
7 changes: 4 additions & 3 deletions src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,10 @@ impl<T> Tree<T> {
fn insert_new_node(&mut self, new_node: Node<T>) -> NodeId {

if self.free_ids.len() > 0 {
let new_node_id: NodeId = self.free_ids
.pop()
.expect("Tree::insert_new_node: Couldn't pop from Vec with len() > 0.");
let new_node_id: NodeId =
self.free_ids
.pop()
.expect("Tree::insert_new_node: Couldn't pop from Vec with len() > 0.");

self.nodes.push(Some(new_node));
self.nodes.swap_remove(new_node_id.index);
Expand Down