Tree

Struct Tree 

Source
pub struct Tree<Inner>
where Inner: MutableGraph,
{ /* private fields */ }
Expand description

A tree is a directed graph in which there is exactly one path between any two nodes.

A tree always has a root node, which is the only node that has no incoming edges.

Implementations§

Source§

impl<Inner> Tree<Inner>
where Inner: MutableGraph,

Source

pub fn new_unchecked(root: NodeID, graph: Inner) -> Self

Source

pub fn new_with_root_and_graph(root: NodeID, graph: Inner) -> Result<Self>

Source

pub fn graph(&self) -> &Inner

Source§

impl<Inner> Tree<Inner>
where Inner: MutableGraph + Default + Clone, Inner::NData: Default,

Source

pub fn new_with_root(root: NodeID) -> Self

Source

pub fn new() -> Self

Source§

impl<Inner> Tree<Inner>
where Inner: MutableGraph + Serialize,

Source

pub fn to_json(&self) -> String

Source§

impl<'de, Inner> Tree<Inner>
where Inner: MutableGraph + Deserialize<'de>,

Source

pub fn from_json(json: &'de str) -> Result<Self, Error>

Trait Implementations§

Source§

impl<Inner> Clone for Tree<Inner>
where Inner: MutableGraph + Clone,

Source§

fn clone(&self) -> Tree<Inner>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Inner> Debug for Tree<Inner>
where Inner: MutableGraph + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Inner> Default for Tree<Inner>
where Inner: MutableGraph + Default + Clone, Inner::NData: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, Inner> Deserialize<'de> for Tree<Inner>
where Inner: MutableGraph + Deserialize<'de>,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Inner> Display for Tree<Inner>
where Inner: MutableGraph + Serialize,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Inner> MutableForest for Tree<Inner>
where Inner: MutableGraph,

Source§

fn add_node_with_node_and_edge_data( &mut self, node: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, node_data: Self::NData, edge_data: Self::EData, ) -> Result<()>

Source§

fn remove_node_ungrouping(&mut self, id: impl AsRef<NodeID>) -> Result<()>

Source§

fn remove_node_and_children(&mut self, id: impl AsRef<NodeID>) -> Result<Nodes>

Source§

fn remove_children(&mut self, id: impl AsRef<NodeID>) -> Result<Nodes>

Source§

fn move_node( &mut self, id: impl AsRef<NodeID>, new_parent: Option<impl AsRef<NodeID>>, ) -> Result<()>

Source§

fn set_data(&mut self, data: Self::GData)

Source§

fn set_node_data( &mut self, id: impl AsRef<NodeID>, data: Self::NData, ) -> Result<()>

Source§

fn set_edge_data( &mut self, id: impl AsRef<EdgeID>, data: Self::EData, ) -> Result<()>

Source§

fn with_data(&mut self, transform: &dyn Fn(&mut Self::GData))

Source§

fn with_node_data( &mut self, id: impl AsRef<NodeID>, transform: &dyn Fn(&mut Self::NData), ) -> Result<()>

Source§

fn with_edge_data( &mut self, id: impl AsRef<EdgeID>, transform: &dyn Fn(&mut Self::EData), ) -> Result<()>

Source§

fn adding_node_with_node_and_edge_data( &self, node: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, node_data: Self::NData, edge_data: Self::EData, ) -> Result<Self>
where Self: Clone + Sized,

Source§

fn removing_node_ungrouping(&self, id: impl AsRef<NodeID>) -> Result<Self>
where Self: Clone + Sized,

Source§

fn removing_node_and_children(&self, id: impl AsRef<NodeID>) -> Result<Self>
where Self: Clone + Sized,

Source§

fn removing_children(&self, id: impl AsRef<NodeID>) -> Result<Self>
where Self: Clone + Sized,

Source§

fn moving_node( &self, id: impl AsRef<NodeID>, new_parent: Option<impl AsRef<NodeID>>, ) -> Result<Self>
where Self: Clone + Sized,

Source§

fn setting_data(&self, data: Self::GData) -> Self
where Self: Clone + Sized,

Source§

fn setting_node_data( &self, id: impl AsRef<NodeID>, data: Self::NData, ) -> Result<Self>
where Self: Clone + Sized,

Source§

fn setting_edge_data( &self, id: impl AsRef<EdgeID>, data: Self::EData, ) -> Result<Self>
where Self: Clone + Sized,

Source§

fn add_node( &mut self, id: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, ) -> Result<()>
where Self::NData: Default, Self::EData: Default,

Source§

fn adding_node( &self, id: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, ) -> Result<Self>
where Self: Clone + Sized, Self::NData: Default, Self::EData: Default,

Source§

fn add_node_with_edge_data( &mut self, id: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, edge_data: Self::EData, ) -> Result<()>
where Self::NData: Default,

Source§

fn adding_node_with_edge_data( &self, id: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, edge_data: Self::EData, ) -> Result<Self>
where Self: Clone + Sized, Self::NData: Default,

Source§

fn add_node_with_node_data( &mut self, id: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, node_data: Self::NData, ) -> Result<()>
where Self::EData: Default,

Source§

fn adding_node_with_node_data( &self, id: impl AsRef<NodeID>, parent: Option<impl AsRef<NodeID>>, edge: impl AsRef<EdgeID>, node_data: Self::NData, ) -> Result<Self>
where Self: Clone + Sized, Self::EData: Default,

Source§

impl<Inner> MutableTree for Tree<Inner>
where Inner: MutableGraph,

Source§

fn set_root(&mut self, root: impl AsRef<NodeID>) -> Result<()>

Source§

fn setting_root(&self, root: impl AsRef<NodeID>) -> Result<Self>
where Self: Clone + Sized,

Source§

impl<Inner> PartialEq for Tree<Inner>
where Inner: MutableGraph + PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Inner> Serialize for Tree<Inner>
where Inner: MutableGraph + Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Inner> VisitableForest for Tree<Inner>
where Inner: MutableGraph,

Source§

fn in_edge(&self, node: impl AsRef<NodeID>) -> Result<Option<EdgeID>>

Source§

fn in_edge_with_root(&self, node: impl AsRef<NodeID>) -> Result<Option<EdgeID>>

Source§

fn parent(&self, node: impl AsRef<NodeID>) -> Result<Option<NodeID>>

Source§

fn children(&self, node: Option<impl AsRef<NodeID>>) -> Result<Nodes>

Source§

fn has_children(&self, node: impl AsRef<NodeID>) -> Result<bool>

Source§

fn child_count(&self, node: impl AsRef<NodeID>) -> Result<usize>

Source§

fn descendants(&self, nodes: &Nodes) -> Result<Nodes>

Source§

fn ancestors(&self, nodes: &Nodes) -> Result<Nodes>

Source§

impl<Inner> VisitableGraph for Tree<Inner>
where Inner: MutableGraph,

Source§

type GData = <Inner as VisitableGraph>::GData

Source§

type NData = <Inner as VisitableGraph>::NData

Source§

type EData = <Inner as VisitableGraph>::EData

Source§

fn data(&self) -> &Self::GData

Returns a reference to the graph’s data.
Source§

fn node_data(&self, id: impl AsRef<NodeID>) -> Result<Cow<'static, Self::NData>>

Returns a reference to the node’s data.
Source§

fn edge_data(&self, id: impl AsRef<EdgeID>) -> Result<Cow<'static, Self::EData>>

Returns a reference to the edge’s data.
Source§

fn is_empty(&self) -> bool

Returns true if the graph is empty.
Source§

fn node_count(&self) -> usize

Returns the number of nodes in the graph.
Source§

fn edge_count(&self) -> usize

Returns the number of edges in the graph.
Source§

fn all_nodes(&self) -> Nodes

Returns a set of all nodes in the graph.
Source§

fn all_edges(&self) -> Edges

Returns a set of all edges in the graph.
Source§

fn has_node(&self, id: impl AsRef<NodeID>) -> bool

Returns true if the graph contains the given node.
Source§

fn has_edge(&self, id: impl AsRef<EdgeID>) -> bool

Returns true if the graph contains the given edge.
Source§

fn has_edge_from_to( &self, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>, ) -> bool

Returns true if the graph contains an edge from source to target.
Source§

fn has_edge_between(&self, a: impl AsRef<NodeID>, b: impl AsRef<NodeID>) -> bool

Returns true if the graph contains an edge between a and b, regardless of direction.
Source§

fn source(&self, id: impl AsRef<EdgeID>) -> Result<NodeID>

Returns the source node of the edge.
Source§

fn target(&self, id: impl AsRef<EdgeID>) -> Result<NodeID>

Returns the target node of the edge.
Source§

fn endpoints(&self, id: impl AsRef<EdgeID>) -> Result<(NodeID, NodeID)>

Returns the endpoints of the edge.
Source§

fn out_edges(&self, id: impl AsRef<NodeID>) -> Result<Edges>

Returns the out-edges of the node.
Source§

fn in_edges(&self, id: impl AsRef<NodeID>) -> Result<Edges>

Returns the in-edges of the node.
Source§

fn incident_edges(&self, id: impl AsRef<NodeID>) -> Result<Edges>

Returns the incident edges of the node.
Source§

fn out_degree(&self, id: impl AsRef<NodeID>) -> Result<usize>

Returns the number of out-edges of the node.
Source§

fn in_degree(&self, id: impl AsRef<NodeID>) -> Result<usize>

Returns the number of in-edges of the node.
Source§

fn degree(&self, id: impl AsRef<NodeID>) -> Result<usize>

Returns the number of incident edges of the node.
Source§

fn successors(&self, id: impl AsRef<NodeID>) -> Result<Nodes>

Returns the immediate successors of the node.
Source§

fn predecessors(&self, id: impl AsRef<NodeID>) -> Result<Nodes>

Returns the immediate predecessors of the node.
Source§

fn neighbors(&self, id: impl AsRef<NodeID>) -> Result<Nodes>

Returns the immediate neighbors of the node.
Source§

fn has_successors(&self, id: impl AsRef<NodeID>) -> Result<bool>

Returns true if the node has successors.
Source§

fn has_predecessors(&self, id: impl AsRef<NodeID>) -> Result<bool>

Returns true if the node has predecessors.
Source§

fn has_neighbors(&self, id: impl AsRef<NodeID>) -> Result<bool>

Returns true if the node has neighbors.
Source§

fn all_roots(&self) -> Nodes

The set of all “roots” (nodes with no predecessors) in the graph.
Source§

fn all_leaves(&self) -> Nodes

The set of all “leaves” (nodes with no successors) in the graph.
Source§

fn non_roots(&self) -> Nodes

The set of all nodes that are not roots (i.e., nodes with at least one predecessor).
Source§

fn non_leaves(&self) -> Nodes

The set of all nodes that are not leaves (i.e., nodes with at least one successor).
Source§

fn all_internals(&self) -> Nodes

The set of all nodes that are neither roots nor leaves (i.e., nodes with at least one predecessor and at least one successor).
Source§

fn is_leaf(&self, id: impl AsRef<NodeID>) -> Result<bool>

Returns true if the node is a leaf (i.e., has no successors).
Source§

fn is_root(&self, id: impl AsRef<NodeID>) -> Result<bool>

Returns true if the node is a root (i.e., has no predecessors).
Source§

fn is_internal(&self, id: impl AsRef<NodeID>) -> Result<bool>

Returns true if the node is neither a root nor a leaf (i.e., has at least one predecessor and at least one successor).
Source§

fn elements(&self) -> Elements

Returns the set of all elements in the graph.
Source§

fn edges_from_to( &self, source: impl AsRef<NodeID>, target: impl AsRef<NodeID>, ) -> Result<Edges>

Returns the edges that have the given source and target nodes. Read more
Source§

fn edges_between( &self, a: impl AsRef<NodeID>, b: impl AsRef<NodeID>, ) -> Result<Edges>

Returns the edges that have the given nodes as endpoints. Read more
Source§

fn edges_from_to_nodes(&self, sources: &Nodes, targets: &Nodes) -> Result<Edges>

Returns the edges connecting the given source nodes to the given target nodes.
Source§

fn edges_between_nodes(&self, a: &Nodes, b: &Nodes) -> Result<Edges>

Returns the edges connecting the given sets of nodes.
Source§

fn nodes_successors(&self, ids: &Nodes) -> Result<Nodes>

Returns the immediate successors of all the given nodes.
Source§

fn nodes_predecessors(&self, ids: &Nodes) -> Result<Nodes>

Returns the immediate predecessors of all the given nodes.
Source§

fn transitive_successors(&self, ids: &Nodes) -> Result<Nodes>

Returns the transitive successors of all the given nodes (i.e., all the nodes reachable from the out-edges of the given nodes). Read more
Source§

fn transitive_predecessors(&self, ids: &Nodes) -> Result<Nodes>

Returns the transitive predecessors of all the given nodes (i.e., all the nodes reachable from the in-edges of the given nodes). Read more
Source§

impl<Inner> VisitableTree for Tree<Inner>
where Inner: MutableGraph,

Source§

fn root(&self) -> NodeID

Source§

impl<Inner> Eq for Tree<Inner>
where Inner: MutableGraph + Eq,

Auto Trait Implementations§

§

impl<Inner> Freeze for Tree<Inner>
where Inner: Freeze,

§

impl<Inner> RefUnwindSafe for Tree<Inner>
where Inner: RefUnwindSafe,

§

impl<Inner> Send for Tree<Inner>
where Inner: Send,

§

impl<Inner> Sync for Tree<Inner>
where Inner: Sync,

§

impl<Inner> Unpin for Tree<Inner>
where Inner: Unpin,

§

impl<Inner> UnwindSafe for Tree<Inner>
where Inner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<G, O> DepthFirstSearch<G, O> for G
where G: VisitableGraph,

Source§

fn depth_first_search_opt<Visitor>( &self, visitor: &mut Visitor, roots: &BTreeSet<NodeID>, roots_only: bool, excluded_edge: Option<impl AsRef<EdgeID>>, ) -> Result<O, Error>
where Visitor: DFSVisitor<Graph = G, Output = O>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<G> IsTree for G

Source§

type Graph = G

Source§

fn is_tree(&self, root: impl AsRef<NodeID>) -> bool

Source§

fn check_is_tree(&self, root: impl AsRef<NodeID>) -> Result<()>

Source§

impl<G> PathExists for G

Source§

type Graph = G

Source§

fn path_exists_opt( &self, from: impl AsRef<NodeID>, to: impl AsRef<NodeID>, excluded_edge: Option<impl AsRef<EdgeID>>, ) -> Result<bool, Error>

Source§

fn path_exists( &self, from: impl AsRef<NodeID>, to: impl AsRef<NodeID>, ) -> Result<bool>

Source§

fn can_add_dag_edge( &self, from: impl AsRef<NodeID>, to: impl AsRef<NodeID>, excluded_edge: Option<impl AsRef<EdgeID>>, ) -> Result<bool>

Source§

fn can_move_dag_edge( &self, edge: impl AsRef<EdgeID>, new_source: impl AsRef<NodeID>, new_target: impl AsRef<NodeID>, ) -> Result<bool>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<G> TopologicalSort for G
where G: VisitableGraph,

Source§

type Graph = G

Source§

fn topological_sort_opt( &self, roots: &BTreeSet<NodeID>, roots_only: bool, ) -> Result<Vec<NodeID>, Error>

Returns reverse-order of topological sort.
Source§

fn topological_sort(&self) -> Result<Vec<NodeID>>

Returns reverse-order of topological sort.
Source§

fn is_dag(&self) -> bool

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,