Skip to content
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orx-tree"
version = "1.10.0"
version = "2.0.0"
edition = "2024"
authors = ["orxfun <[email protected]>"]
description = "A beautiful tree 🌳 with convenient, efficient, parallelizable growth, mutation and traversal features."
Expand All @@ -17,7 +17,7 @@ orx-self-or = "1.2.0"
serde = { version = "1.0.228", optional = true, default-features = false }
orx-pinned-vec = { version = "3.21.0", default-features = false }
orx-split-vec = { version = "3.22.0", default-features = false }
orx-selfref-col = { version = "2.15.0", default-features = false }
orx-selfref-col = { version = "3.0.0", default-features = false }
orx-concurrent-iter = { version = "3.1.0", default-features = false }
orx-parallel = { version = "3.3.0", default-features = false, optional = true }

Expand Down
130 changes: 65 additions & 65 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benches/children_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn build_tree(n: usize) -> DynTree<String> {
while tree.len() < n {
let root = tree.root();
let x: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in x.iter() {
for idx in x {
let count = tree.len();
let mut node = tree.node_mut(idx);
let num_children = 4;
Expand Down
2 changes: 1 addition & 1 deletion benches/parallelization_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn build_tree(n: usize) -> DynTree<String> {
while tree.len() < n {
let root = tree.root();
let x: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in x.iter() {
for idx in x {
let count = tree.len();
let mut node = tree.node_mut(idx);
let num_children = 20;
Expand Down
2 changes: 1 addition & 1 deletion benches/parallelization_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn build_tree(n: usize) -> DynTree<String> {
while tree.len() < n {
let root = tree.root();
let x: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in x.iter() {
for idx in x {
let count = tree.len();
let mut node = tree.node_mut(idx);
let num_children = 20;
Expand Down
2 changes: 1 addition & 1 deletion benches/paths_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn build_tree(n: usize) -> DynTree<String> {
while tree.len() < n {
let root = tree.root();
let x: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in x.iter() {
for idx in x {
let count = tree.len();
let mut node = tree.node_mut(idx);
let num_children = 4;
Expand Down
2 changes: 1 addition & 1 deletion benches/walk_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn build_tree(n: usize) -> DynTree<String> {
while tree.len() < n {
let root = tree.root();
let x: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in x.iter() {
for idx in x {
let count = tree.len();
let mut node = tree.node_mut(idx);
let num_children = 10;
Expand Down
2 changes: 1 addition & 1 deletion examples/bench_parallelization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn build_tree(total_depth: usize) -> DaryTree<4, usize> {
let leaves: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in leaves {
let count = tree.len();
let mut node = tree.node_mut(&idx);
let mut node = tree.node_mut(idx);
for j in 0..4 {
node.push_child(count + j);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo_parallelization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn build_tree(total_depth: usize, num_children: usize) -> DynTree<String> {
let leaves: Vec<_> = root.leaves_with(&mut dfs).map(|x| x.idx()).collect();
for idx in leaves {
let count = tree.len();
let mut node = tree.node_mut(&idx);
let mut node = tree.node_mut(idx);
for j in 0..num_children {
node.push_child((count + j).to_string());
}
Expand Down
8 changes: 4 additions & 4 deletions examples/mutable_recursive_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl Instructions {
InstructionNode::new(Instruction::AddI { val: 2.0 }, 0.0),
]);
let _n3 = tree
.node_mut(&n1)
.node_mut(n1)
.push_child(InstructionNode::new(Instruction::Input(0), 0.0));
let [_n4, _n5] = tree.node_mut(&n2).push_children([
let [_n4, _n5] = tree.node_mut(n2).push_children([
InstructionNode::new(Instruction::Add, 0.0),
InstructionNode::new(Instruction::AddI { val: 5.0 }, 0.0),
]);
Expand Down Expand Up @@ -153,15 +153,15 @@ fn recursive_traversal_over_indices(
inputs: &[f32],
node_idx: NodeIdx<Dyn<InstructionNode>>,
) -> f32 {
let node = tree.node(&node_idx);
let node = tree.node(node_idx);

let children_ids: Vec<_> = node.children().map(|child| child.idx()).collect();
let children: Vec<_> = children_ids
.into_iter()
.map(|node| recursive_traversal_over_indices(tree, inputs, node))
.collect();

let mut node = tree.node_mut(&node_idx);
let mut node = tree.node_mut(node_idx);

let new_value = match node.data().instruction {
Instruction::Input(i) => inputs[i],
Expand Down
16 changes: 8 additions & 8 deletions examples/special_iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ fn main() {

let mut root = tree.root_mut();
let [id2, id3] = root.push_children([2, 3]);
let [id4, _] = tree.node_mut(&id2).push_children([4, 5]);
let id8 = tree.node_mut(&id4).push_child(8);
let [id6, id7] = tree.node_mut(&id3).push_children([6, 7]);
tree.node_mut(&id6).push_child(9);
let [_, id11] = tree.node_mut(&id7).push_children([10, 11]);
let [id4, _] = tree.node_mut(id2).push_children([4, 5]);
let id8 = tree.node_mut(id4).push_child(8);
let [id6, id7] = tree.node_mut(id3).push_children([6, 7]);
tree.node_mut(id6).push_child(9);
let [_, id11] = tree.node_mut(id7).push_children([10, 11]);

print!("{}", &tree);
// 1
Expand All @@ -27,9 +27,9 @@ fn main() {
// └──11

let root = tree.root();
let n3 = tree.node(&id3);
let n8 = tree.node(&id8);
let n11 = tree.node(&id11);
let n3 = tree.node(id3);
let n8 = tree.node(id8);
let n11 = tree.node(id11);

// leaves

Expand Down
24 changes: 12 additions & 12 deletions examples/walks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ fn main() {

let mut root = tree.root_mut();
let [id2, id3] = root.push_children([2, 3]);
let [id4, _] = tree.node_mut(&id2).push_children([4, 5]);
tree.node_mut(&id4).push_child(8);
let [id6, id7] = tree.node_mut(&id3).push_children([6, 7]);
tree.node_mut(&id6).push_child(9);
tree.node_mut(&id7).push_children([10, 11]);
let [id4, _] = tree.node_mut(id2).push_children([4, 5]);
tree.node_mut(id4).push_child(8);
let [id6, id7] = tree.node_mut(id3).push_children([6, 7]);
tree.node_mut(id6).push_child(9);
tree.node_mut(id7).push_children([10, 11]);

print!("{}", &tree);
// 1
Expand All @@ -33,14 +33,14 @@ fn main() {
);

// B. breadth-first node values from node 3
let n3 = tree.node(&id3);
let n3 = tree.node(id3);
println!(
"breadth-first node values from root: {:?}",
n3.walk::<Bfs>().collect::<Vec<_>>()
);

// C. post-order node values from node 2
let n2 = tree.node(&id2);
let n2 = tree.node(id2);
println!(
"post-order node values from root: {:?}",
n2.walk::<PostOrder>().collect::<Vec<_>>()
Expand All @@ -53,14 +53,14 @@ fn main() {
[1, 2, 4, 8, 5, 3, 6, 9, 7, 10, 11]
);
assert_eq!(
tree.node(&id2)
tree.node(id2)
.walk_with(&mut t)
.copied()
.collect::<Vec<_>>(),
[2, 4, 8, 5]
);
assert_eq!(
tree.node(&id3)
tree.node(id3)
.walk_with(&mut t)
.copied()
.collect::<Vec<_>>(),
Expand All @@ -70,7 +70,7 @@ fn main() {
// using traversal to traverse over nodes, rather than only data, with access to children and parent
let mut t = Traversal.bfs().over_nodes(); // breadth-first traverser over nodes
let x: Vec<_> = tree
.node(&id3)
.node(id3)
.walk_with(&mut t)
.map(|node| {
let node_value = *node.data();
Expand All @@ -85,14 +85,14 @@ fn main() {

// using traversal to additionally access to depth and sibling indices
let mut t = Traversal.dfs().with_depth();
let n2 = tree.node(&id2);
let n2 = tree.node(id2);
println!(
"depth-first (depth, node value) pairs from n2: {:?}",
n2.walk_with(&mut t).collect::<Vec<_>>()
);

let mut t = Traversal.dfs().with_depth().with_sibling_idx();
let n3 = tree.node(&id3);
let n3 = tree.node(id3);
println!(
"depth-first (depth, sibling index, node value) tuples from n3: {:?}",
n3.walk_with(&mut t).collect::<Vec<_>>()
Expand Down
20 changes: 10 additions & 10 deletions src/common_traits/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ where
/// let mut root = tree.root_mut();
/// let [id1, id2] = root.push_children([1, 2]);
///
/// let mut n1 = tree.node_mut(&id1);
/// let mut n1 = tree.node_mut(id1);
/// let [id3, _] = n1.push_children([3, 4]);
///
/// tree.node_mut(&id3).push_child(7);
/// tree.node_mut(id3).push_child(7);
///
/// let mut n2 = tree.node_mut(&id2);
/// let mut n2 = tree.node_mut(id2);
/// let [id5, id6] = n2.push_children([5, 6]);
///
/// tree.node_mut(&id5).push_child(8);
/// tree.node_mut(&id6).push_children([9, 10]);
/// tree.node_mut(id5).push_child(8);
/// tree.node_mut(id6).push_children([9, 10]);
///
/// let bfs: Vec<_> = tree.root().walk::<Bfs>().copied().collect();
/// assert_eq!(bfs, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
Expand All @@ -59,13 +59,13 @@ where
///
/// let indices: Vec<_> = clone.root().indices::<Bfs>().collect();
///
/// assert_eq!(tree.get_node(&indices[2]), None);
/// assert_eq!(tree.try_node(&indices[2]), Err(NodeIdxError::OutOfBounds));
/// assert_eq!(tree.get_node(indices[2]), None);
/// assert_eq!(tree.try_node(indices[2]), Err(NodeIdxError::OutOfBounds));
///
/// assert_eq!(clone.get_node(&id2), None);
/// assert_eq!(clone.try_node(&id2), Err(NodeIdxError::OutOfBounds));
/// assert_eq!(clone.get_node(id2), None);
/// assert_eq!(clone.try_node(id2), Err(NodeIdxError::OutOfBounds));
///
/// assert_eq!(clone.node(&indices[2]).data(), &2);
/// assert_eq!(clone.node(indices[2]).data(), &2);
/// ```
fn clone(&self) -> Self {
match self.get_root() {
Expand Down
42 changes: 21 additions & 21 deletions src/common_traits/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ where
///
/// let mut root = tree.root_mut();
/// let [id2, id3] = root.push_children([2, 3]);
/// let [id4, _] = tree.node_mut(&id2).push_children([4, 5]);
/// tree.node_mut(&id4).push_child(8);
/// let [id6, id7] = tree.node_mut(&id3).push_children([6, 7]);
/// tree.node_mut(&id6).push_child(9);
/// tree.node_mut(&id7).push_children([10, 11]);
/// let [id4, _] = tree.node_mut(id2).push_children([4, 5]);
/// tree.node_mut(id4).push_child(8);
/// let [id6, id7] = tree.node_mut(id3).push_children([6, 7]);
/// tree.node_mut(id6).push_child(9);
/// tree.node_mut(id7).push_children([10, 11]);
///
/// let expected_str = r#"1
/// ├──2
Expand All @@ -60,8 +60,8 @@ where
/// ├──10
/// └──11
/// "#;
/// println!("{}", tree.node(&id3).to_string());
/// assert_eq!(tree.node(&id3).to_string(), expected_str);
/// println!("{}", tree.node(id3).to_string());
/// assert_eq!(tree.node(id3).to_string(), expected_str);
/// ```
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut t = Traversal.dfs().over_nodes().with_depth().with_sibling_idx();
Expand Down Expand Up @@ -96,11 +96,11 @@ where
///
/// let mut root = tree.root_mut();
/// let [id2, id3] = root.push_children([2, 3]);
/// let [id4, _] = tree.node_mut(&id2).push_children([4, 5]);
/// tree.node_mut(&id4).push_child(8);
/// let [id6, id7] = tree.node_mut(&id3).push_children([6, 7]);
/// tree.node_mut(&id6).push_child(9);
/// tree.node_mut(&id7).push_children([10, 11]);
/// let [id4, _] = tree.node_mut(id2).push_children([4, 5]);
/// tree.node_mut(id4).push_child(8);
/// let [id6, id7] = tree.node_mut(id3).push_children([6, 7]);
/// tree.node_mut(id6).push_child(9);
/// tree.node_mut(id7).push_children([10, 11]);
///
/// let expected_str = r#"1
/// ├──2
Expand All @@ -123,8 +123,8 @@ where
/// ├──10
/// └──11
/// "#;
/// println!("{}", tree.node(&id3).to_string());
/// assert_eq!(tree.node(&id3).to_string(), expected_str);
/// println!("{}", tree.node(id3).to_string());
/// assert_eq!(tree.node(id3).to_string(), expected_str);
/// ```
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut t = Traversal.dfs().over_nodes().with_depth().with_sibling_idx();
Expand Down Expand Up @@ -159,11 +159,11 @@ where
///
/// let mut root = tree.root_mut();
/// let [id2, id3] = root.push_children([2, 3]);
/// let [id4, _] = tree.node_mut(&id2).push_children([4, 5]);
/// tree.node_mut(&id4).push_child(8);
/// let [id6, id7] = tree.node_mut(&id3).push_children([6, 7]);
/// tree.node_mut(&id6).push_child(9);
/// tree.node_mut(&id7).push_children([10, 11]);
/// let [id4, _] = tree.node_mut(id2).push_children([4, 5]);
/// tree.node_mut(id4).push_child(8);
/// let [id6, id7] = tree.node_mut(id3).push_children([6, 7]);
/// tree.node_mut(id6).push_child(9);
/// tree.node_mut(id7).push_children([10, 11]);
///
/// let expected_str = r#"1
/// ├──2
Expand All @@ -186,8 +186,8 @@ where
/// ├──10
/// └──11
/// "#;
/// println!("{}", tree.node(&id3).to_string());
/// assert_eq!(tree.node(&id3).to_string(), expected_str);
/// println!("{}", tree.node(id3).to_string());
/// assert_eq!(tree.node(id3).to_string(), expected_str);
/// ```
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.get_root() {
Expand Down
18 changes: 9 additions & 9 deletions src/common_traits/into_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ where
/// let mut root = tree.root_mut();
/// let [id1, id2] = root.push_children([1, 2]);
///
/// let mut n1 = tree.node_mut(&id1);
/// let mut n1 = tree.node_mut(id1);
/// let [id3, _] = n1.push_children([3, 4]);
///
/// tree.node_mut(&id3).push_child(7);
/// tree.node_mut(id3).push_child(7);
///
/// let mut n2 = tree.node_mut(&id2);
/// let mut n2 = tree.node_mut(id2);
/// n2.push_children([5, 6]);
///
/// // transform the tree into an arbitrary order iterator
Expand Down Expand Up @@ -142,12 +142,12 @@ where
/// let mut root = tree.root_mut();
/// let [id1, id2] = root.push_children([1, 2]);
///
/// let mut n1 = tree.node_mut(&id1);
/// let mut n1 = tree.node_mut(id1);
/// let [id3, _] = n1.push_children([3, 4]);
///
/// tree.node_mut(&id3).push_child(7);
/// tree.node_mut(id3).push_child(7);
///
/// let mut n2 = tree.node_mut(&id2);
/// let mut n2 = tree.node_mut(id2);
/// n2.push_children([5, 6]);
///
/// // iterate over the tree in an arbitrary order
Expand Down Expand Up @@ -245,12 +245,12 @@ where
/// let mut root = tree.root_mut();
/// let [id1, id2] = root.push_children([1, 2]);
///
/// let mut n1 = tree.node_mut(&id1);
/// let mut n1 = tree.node_mut(id1);
/// let [id3, _] = n1.push_children([3, 4]);
///
/// tree.node_mut(&id3).push_child(7);
/// tree.node_mut(id3).push_child(7);
///
/// let mut n2 = tree.node_mut(&id2);
/// let mut n2 = tree.node_mut(id2);
/// n2.push_children([5, 6]);
///
/// // mutably iterate over the tree in an arbitrary order
Expand Down
Loading