Skip to content

Commit

Permalink
chore(release): 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
antouhou authored Jun 3, 2024
2 parents 4bcfaad + 5d3b89e commit 1bbf48c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build and test

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
test:
Expand Down
24 changes: 21 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
[package]
name = "easy-tree"
version = "0.1.0"
authors = ["Anton Suprunchuk <[email protected]>"]
edition = "2021"
description = "A simple and efficient tree structure library for Rust with recursive traversal"
homepage = "https://github.com/antouhou/easy-tree"
repository = "https://github.com/antouhou/easy-tree"
license = "MIT"
keywords = ["tree", "traversal", "data_structure", "hierarchical", "recursive"]
categories = ["data-structures", "algorithms"]
readme = "README.md"

[dependencies.rayon]
version = "1.10.0"
optional = true
[dependencies]
# Add other dependencies here
rayon = { version = "1.10", optional = true }

[features]
default = []

[badges]
github-actions = { repository = "antouhou/easy-tree" }

# For documentation purpose
[package.metadata.docs.rs]
features = ["rayon"]
50 changes: 29 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ impl<T> Tree<T> {

/// Adds a child node with the given data to the root node and returns the child's index.
pub fn add_child_to_root(&mut self, data: T) -> usize {
let index = self.add_child(0, data);

index
self.add_child(0, data)
}

/// Returns a reference to the data of the node at the given index, or `None` if the index is
Expand Down Expand Up @@ -317,26 +315,36 @@ mod tests {
let mut tree = Tree::new();
let root = tree.add_node(0); // Root node with data 0
let child1 = tree.add_child(root, 1); // Child node with data 1
let child2 = tree.add_child(root, 2); // Child node with data 2
let child3 = tree.add_child(child1, 3); // Child node with data 3
let _child2 = tree.add_child(root, 2); // Child node with data 2
let _child3 = tree.add_child(child1, 3); // Child node with data 3

let mut result = vec![];

tree.traverse(|index, node, result| {
result.push(format!("Calling handler for node {}: {}", index, node))
}, |index, node, result| {
result.push(format!("Finished handling node {} and all it's children", index))
}, &mut result);

assert_eq!(result, vec![
"Calling handler for node 0: 0",
"Calling handler for node 1: 1",
"Calling handler for node 3: 3",
"Finished handling node 3 and all it's children",
"Finished handling node 1 and all it's children",
"Calling handler for node 2: 2",
"Finished handling node 2 and all it's children",
"Finished handling node 0 and all it's children",
]);
tree.traverse(
|index, node, result| {
result.push(format!("Calling handler for node {}: {}", index, node))
},
|index, _node, result| {
result.push(format!(
"Finished handling node {} and all it's children",
index
))
},
&mut result,
);

assert_eq!(
result,
vec![
"Calling handler for node 0: 0",
"Calling handler for node 1: 1",
"Calling handler for node 3: 3",
"Finished handling node 3 and all it's children",
"Finished handling node 1 and all it's children",
"Calling handler for node 2: 2",
"Finished handling node 2 and all it's children",
"Finished handling node 0 and all it's children",
]
);
}
}

0 comments on commit 1bbf48c

Please sign in to comment.