Skip to content

2024edition #157

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 7 commits into from
Apr 11, 2025
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
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Rust

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

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
toolchain: ["stable"]

steps:
- uses: actions/checkout@v4

- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}

- name: Install 32bit target
run: rustup target add i686-unknown-linux-musl
- name: Install wasm target
run: rustup target add wasm32v1-none
- name: Install miri
run: rustup component add --toolchain nightly-x86_64-unknown-linux-gnu miri
- name: Install no-std-check
run: cargo install cargo-no-std-check

- name: Build
run: cargo build --features serde --verbose
- name: Build-32bit
run: cargo build --features serde --verbose --target i686-unknown-linux-musl
- name: Build-wasm
run: cargo build --features serde --verbose --target wasm32v1-none

- name: Test
run: cargo test --features serde --verbose
- name: Test-32bit
run: cargo test --features serde --verbose --target i686-unknown-linux-musl
- name: Check-wasm
run: cargo check --features serde --verbose --target wasm32v1-none

- name: Clippy
run: cargo clippy --features serde -- -D warnings --verbose

- name: Miri
run: cargo +nightly miri test --features serde --verbose

- name: NoStd
run: cargo +nightly no-std-check --features serde
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "orx-tree"
version = "1.3.0"
edition = "2021"
version = "1.4.0"
edition = "2024"
authors = ["orxfun <[email protected]>"]
description = "A beautiful tree 🌳 with convenient and efficient growth, mutation and traversal features."
license = "MIT OR Apache-2.0"
Expand All @@ -10,17 +10,18 @@ keywords = ["tree", "data-structures", "traversal", "traverse", "binarytree"]
categories = ["data-structures", "algorithms", "rust-patterns", "no-std"]

[dependencies]
orx-pseudo-default = { version = "2.0.0", default-features = false }
orx-pinned-vec = "3.15"
orx-split-vec = "3.15"
orx-selfref-col = "2.7"
orx-self-or = "1.1.1"
orx-iterable = "1.2.0"
serde = { version = "1.0.217", optional = true, default-features = false }
orx-iterable = { version = "1.3.0", default-features = false }
orx-pseudo-default = { version = "2.1.0", default-features = false }
orx-pinned-vec = "3.16.0"
orx-split-vec = "3.16.0"
orx-selfref-col = "2.8.0"
orx-self-or = "1.2.0"
serde = { version = "1.0.219", optional = true, default-features = false }


[dev-dependencies]
test-case = { version = "3.3.1", default-features = false }
serde_json = { version = "1.0.138", default-features = false, features = [
serde_json = { version = "1.0.140", default-features = false, features = [
"std",
] }

Expand Down
2 changes: 1 addition & 1 deletion src/common_traits/clone.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{memory::MemoryPolicy, pinned_storage::PinnedStorage, NodeRef, Tree, TreeVariant};
use crate::{NodeRef, Tree, TreeVariant, memory::MemoryPolicy, pinned_storage::PinnedStorage};

impl<V, M, P> Clone for Tree<V, M, P>
where
Expand Down
4 changes: 2 additions & 2 deletions src/common_traits/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
memory::MemoryPolicy, pinned_storage::PinnedStorage, traversal::traverser_core::TraverserCore,
Node, NodeMut, NodeRef, Traversal, Traverser, Tree, TreeVariant,
Node, NodeMut, NodeRef, Traversal, Traverser, Tree, TreeVariant, memory::MemoryPolicy,
pinned_storage::PinnedStorage, traversal::traverser_core::TraverserCore,
};
use core::fmt::Debug;

Expand Down
4 changes: 2 additions & 2 deletions src/common_traits/display.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
pinned_storage::PinnedStorage, traversal::OverDepthSiblingIdxNode, Dfs, MemoryPolicy, Node,
NodeMut, NodeRef, Traversal, Traverser, Tree, TreeVariant,
Dfs, MemoryPolicy, Node, NodeMut, NodeRef, Traversal, Traverser, Tree, TreeVariant,
pinned_storage::PinnedStorage, traversal::OverDepthSiblingIdxNode,
};
use alloc::string::ToString;
use alloc::vec::Vec;
Expand Down
2 changes: 1 addition & 1 deletion src/common_traits/eq.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{pinned_storage::PinnedStorage, Dfs, MemoryPolicy, NodeRef, Tree, TreeVariant};
use crate::{Dfs, MemoryPolicy, NodeRef, Tree, TreeVariant, pinned_storage::PinnedStorage};

impl<V1, M1, P1, V2, M2, P2> PartialEq<Tree<V1, M1, P1>> for Tree<V2, M2, P2>
where
Expand Down
4 changes: 2 additions & 2 deletions src/common_traits/equality.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
memory::MemoryPolicy, node_ref::NodeRefCore, pinned_storage::PinnedStorage, Node, NodeMut,
TreeVariant,
Node, NodeMut, TreeVariant, memory::MemoryPolicy, node_ref::NodeRefCore,
pinned_storage::PinnedStorage,
};

impl<V, M, P> PartialEq for Node<'_, V, M, P>
Expand Down
2 changes: 1 addition & 1 deletion src/common_traits/from_depth_first_iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{pinned_storage::PinnedStorage, MemoryPolicy, Tree, TreeVariant};
use crate::{MemoryPolicy, Tree, TreeVariant, pinned_storage::PinnedStorage};

/// A depth first sequence is a representation of a tree in a linear storage of (depth, value) tuples.
/// This is useful in collecting trees from iterators, (de)-serializing trees or converting its variant
Expand Down
2 changes: 1 addition & 1 deletion src/common_traits/into_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{aliases::N, pinned_storage::PinnedStorage, MemoryPolicy, Tree, TreeVariant};
use crate::{MemoryPolicy, Tree, TreeVariant, aliases::N, pinned_storage::PinnedStorage};
use core::iter::FusedIterator;
use orx_iterable::{Collection, CollectionMut, Iterable};

Expand Down
14 changes: 10 additions & 4 deletions src/common_traits/serde.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
pinned_storage::PinnedStorage, MemoryPolicy, NodeRef, Traversal, Traverser, Tree, TreeVariant,
MemoryPolicy, NodeRef, Traversal, Traverser, Tree, TreeVariant, pinned_storage::PinnedStorage,
};
use core::marker::PhantomData;
use serde::{de::Visitor, ser::SerializeSeq, Deserialize, Serialize};
use serde::{Deserialize, Serialize, de::Visitor, ser::SerializeSeq};

// Serialize

Expand Down Expand Up @@ -104,7 +104,10 @@ where
if let Some(x) = seq.next_element()? {
let (depth, value): (usize, V::Item) = x;
if depth != 0 {
return err(format!("First element of DepthFirstSequence (root of the tree) must have depth 0; however, received a depth of {}. Following is an example valid sequence of (depth, value) pairs: [[0, 0], [1, 1], [2, 3], [3, 6], [1, 2], [2, 4], [2, 5], [3, 7]].", depth));
return err(format!(
"First element of DepthFirstSequence (root of the tree) must have depth 0; however, received a depth of {}. Following is an example valid sequence of (depth, value) pairs: [[0, 0], [1, 1], [2, 3], [3, 6], [1, 2], [2, 4], [2, 5], [3, 7]].",
depth
));
}
tree.push_root(value);

Expand All @@ -116,7 +119,10 @@ where
match depth > current_depth {
true => {
if depth > current_depth + 1 {
return err(format!("Let d1 and d2 be two consecutive depths in the depth-first sequence. Then, (i) d2=d1+1, (ii) d2=d1 or (iii) d2<d1 are valid cases. However, received the invalid case where d2>d1+1 (d1={}, d2={}). Please see DepthFirstSequenceError documentation for details. Following is an example valid sequence of (depth, value) pairs: [[0, 0], [1, 1], [2, 3], [3, 6], [1, 2], [2, 4], [2, 5], [3, 7]].", current_depth, depth));
return err(format!(
"Let d1 and d2 be two consecutive depths in the depth-first sequence. Then, (i) d2=d1+1, (ii) d2=d1 or (iii) d2<d1 are valid cases. However, received the invalid case where d2>d1+1 (d1={}, d2={}). Please see DepthFirstSequenceError documentation for details. Following is an example valid sequence of (depth, value) pairs: [[0, 0], [1, 1], [2, 3], [3, 6], [1, 2], [2, 4], [2, 5], [3, 7]].",
current_depth, depth
));
}
}
false => {
Expand Down
2 changes: 1 addition & 1 deletion src/dary/aliases.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Dary;
use crate::{memory::Auto, pinned_storage::SplitRecursive, Node, Tree};
use crate::{Node, Tree, memory::Auto, pinned_storage::SplitRecursive};

/// A binary tree where each of the nodes might have at most 2 children.
pub type Binary<T> = Dary<2, T>;
Expand Down
2 changes: 1 addition & 1 deletion src/dyn/aliases.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Dyn;
use crate::{memory::Auto, pinned_storage::SplitRecursive, Node, Tree};
use crate::{Node, Tree, memory::Auto, pinned_storage::SplitRecursive};

/// A dynamic tree where each of the nodes might have any number of child nodes.
///
Expand Down
2 changes: 1 addition & 1 deletion src/iter/children_mut.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
NodeMut, TreeVariant,
aliases::{Col, N},
memory::MemoryPolicy,
node_mut::NodeMutDown,
pinned_storage::PinnedStorage,
tree_variant::RefsChildren,
NodeMut, TreeVariant,
};
use orx_selfref_col::NodePtr;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ mod tree_variant;

pub use common_traits::{DepthFirstSequence, DepthFirstSequenceError};
pub use dary::{Binary, BinaryNode, BinaryTree, Dary, DaryNode, DaryTree};
pub use r#dyn::{Dyn, DynNode, DynTree};
pub use memory::{Auto, AutoWithThreshold, Lazy, MemoryPolicy};
pub use node::Node;
pub use node_mut::{NodeMut, NodeMutDown, NodeMutOrientation, NodeMutUpAndDown, Side};
pub use node_ref::NodeRef;
pub use r#dyn::{Dyn, DynNode, DynTree};
pub use subtrees::SubTree;
pub use traversal::{Bfs, Dfs, PostOrder, Traversal, Traverser};
pub use tree::Tree;
Expand Down
2 changes: 1 addition & 1 deletion src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{pinned_storage::PinnedStorage, Tree, TreeVariant};
use crate::{Tree, TreeVariant, pinned_storage::PinnedStorage};
use orx_selfref_col::{MemoryReclaimNever, MemoryReclaimOnThreshold, MemoryReclaimer, Utilization};

/// Trees use a pinned vector ([`PinnedVec`]) as its underlying storage.
Expand Down
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
TreeVariant,
aliases::Col,
memory::{Auto, MemoryPolicy},
node_ref::NodeRefCore,
pinned_storage::{PinnedStorage, SplitRecursive},
TreeVariant,
};
use orx_selfref_col::NodePtr;

Expand Down
13 changes: 8 additions & 5 deletions src/node_mut.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
NodeIdx, NodeRef, SubTree, Traverser, Tree, TreeVariant,
aliases::{Col, N},
iter::ChildrenMutIter,
memory::{Auto, MemoryPolicy},
Expand All @@ -7,14 +8,13 @@ use crate::{
subtrees::{MovedSubTree, SubTreeCore},
subtrees_within::SubTreeWithin,
traversal::{
OverData, OverMut,
enumerations::Val,
over_mut::{OverItemInto, OverItemMut},
post_order::iter_ptr::PostOrderIterPtr,
OverData, OverMut,
},
tree_node_idx::INVALID_IDX_ERROR,
tree_variant::RefsChildren,
NodeIdx, NodeRef, SubTree, Traverser, Tree, TreeVariant,
};
use core::{fmt::Debug, marker::PhantomData};
use orx_selfref_col::{NodePtr, Refs};
Expand Down Expand Up @@ -1627,7 +1627,10 @@ where
/// assert_eq!(bfs, [1, 4, 5, 3, 8, 6, 10, 11, 9]);
/// ```
pub fn take_out(self) -> V::Item {
assert!(!self.is_root() || self.num_children() == 1, "If taken out node is the root, it must have only one child which will be the new root.");
assert!(
!self.is_root() || self.num_children() == 1,
"If taken out node is the root, it must have only one child which will be the new root."
);

let parent_ptr = self.parent_ptr();
let sibling_idx = self.sibling_idx();
Expand Down Expand Up @@ -1968,8 +1971,8 @@ where
pub fn children_mut(
&mut self,
) -> impl ExactSizeIterator<Item = NodeMut<'_, V, M, P, NodeMutDown>>
+ DoubleEndedIterator
+ use<'_, 'a, V, M, P, MO> {
+ DoubleEndedIterator
+ use<'_, 'a, V, M, P, MO> {
ChildrenMutIter::new(self.col, self.node_ptr.ptr())
}

Expand Down
4 changes: 2 additions & 2 deletions src/node_ref.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use crate::{
Dfs, Node, NodeIdx, Traverser, Tree, TreeVariant,
aliases::{Col, N},
iter::AncestorsIterPtr,
memory::MemoryPolicy,
pinned_storage::PinnedStorage,
subtrees::{ClonedSubTree, CopiedSubTree},
traversal::{
Over, OverData,
enumeration::Enumeration,
enumerations::Val,
over::{OverDepthPtr, OverItem},
traverser_core::TraverserCore,
Over, OverData,
},
tree_variant::RefsChildren,
Dfs, Node, NodeIdx, Traverser, Tree, TreeVariant,
};
use orx_selfref_col::{NodePtr, Refs};

Expand Down
2 changes: 1 addition & 1 deletion src/pinned_storage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{aliases::N, TreeVariant};
use crate::{TreeVariant, aliases::N};
use orx_split_vec::{PinnedVec, Recursive, SplitVec};

/// Trait defining the underlying pinned vector storage of the tree.
Expand Down
2 changes: 1 addition & 1 deletion src/subtrees/cloned_subtree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::subtree::sealed::SubTreeCore;
use crate::{
Dfs, MemoryPolicy, NodeRef, TreeVariant,
pinned_storage::PinnedStorage,
traversal::{over::OverDepthPtr, traverser_core::TraverserCore},
Dfs, MemoryPolicy, NodeRef, TreeVariant,
};
use core::marker::PhantomData;
use orx_selfref_col::NodePtr;
Expand Down
2 changes: 1 addition & 1 deletion src/subtrees/copied_subtree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::subtree::sealed::SubTreeCore;
use crate::{
Dfs, MemoryPolicy, NodeRef, TreeVariant,
pinned_storage::PinnedStorage,
traversal::{over::OverDepthPtr, traverser_core::TraverserCore},
Dfs, MemoryPolicy, NodeRef, TreeVariant,
};
use core::marker::PhantomData;
use orx_selfref_col::NodePtr;
Expand Down
2 changes: 1 addition & 1 deletion src/subtrees/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ mod tree_as_subtree;
pub use cloned_subtree::ClonedSubTree;
pub use copied_subtree::CopiedSubTree;
pub use moved_subtree::MovedSubTree;
pub(crate) use subtree::sealed::SubTreeCore;
pub use subtree::SubTree;
pub(crate) use subtree::sealed::SubTreeCore;
4 changes: 2 additions & 2 deletions src/subtrees/moved_subtree.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::subtree::sealed::SubTreeCore;
use crate::{
Dfs, MemoryPolicy, NodeMut, NodeMutOrientation, NodeRef, TreeVariant,
node_ref::NodeRefCore,
pinned_storage::PinnedStorage,
traversal::{traverser_core::TraverserCore, OverDepthData},
Dfs, MemoryPolicy, NodeMut, NodeMutOrientation, NodeRef, TreeVariant,
traversal::{OverDepthData, traverser_core::TraverserCore},
};
use orx_selfref_col::NodePtr;

Expand Down
4 changes: 2 additions & 2 deletions src/subtrees/subtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::TreeVariant;
pub(crate) mod sealed {

use crate::{
pinned_storage::PinnedStorage, DepthFirstSequence, MemoryPolicy, NodeIdx, NodeMut,
NodeMutOrientation, Tree, TreeVariant,
DepthFirstSequence, MemoryPolicy, NodeIdx, NodeMut, NodeMutOrientation, Tree, TreeVariant,
pinned_storage::PinnedStorage,
};
use orx_selfref_col::NodePtr;

Expand Down
2 changes: 1 addition & 1 deletion src/subtrees/tree_as_subtree.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::subtree::sealed::SubTreeCore;
use crate::{
Dfs, MemoryPolicy, Tree, TreeVariant,
node_ref::NodeRefCore,
pinned_storage::PinnedStorage,
traversal::{over::OverDepthData, traverser_core::TraverserCore},
Dfs, MemoryPolicy, Tree, TreeVariant,
};
use orx_selfref_col::NodePtr;

Expand Down
2 changes: 1 addition & 1 deletion src/subtrees_within/cloned_subtree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::subtree_within::sealed::SubTreeWithinCore;
use crate::{
Dfs, MemoryPolicy, NodeIdx, NodeMut, NodeMutOrientation, TreeVariant,
pinned_storage::PinnedStorage,
traversal::{over::OverDepthPtr, traverser_core::TraverserCore},
Dfs, MemoryPolicy, NodeIdx, NodeMut, NodeMutOrientation, TreeVariant,
};

pub struct ClonedSubTreeWithin<V: TreeVariant>
Expand Down
2 changes: 1 addition & 1 deletion src/subtrees_within/copied_subtree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::subtree_within::sealed::SubTreeWithinCore;
use crate::{
Dfs, MemoryPolicy, NodeIdx, NodeMut, NodeMutOrientation, TreeVariant,
pinned_storage::PinnedStorage,
traversal::{over::OverDepthPtr, traverser_core::TraverserCore},
Dfs, MemoryPolicy, NodeIdx, NodeMut, NodeMutOrientation, TreeVariant,
};

pub struct CopiedSubTreeWithin<V: TreeVariant>
Expand Down
Loading