pub enum NodeType {
Input,
Output,
Vertex,
Edge,
Leaf,
Root,
}Expand description
NodeType is a soft identification for different nodes within a graph or tree structure.
Most of the time when reading a node’s type, we can determine what kind of node it is by the connections around it. For example, in a graph, if a node has 0 incoming connections, it is likely an Input. Inversely, if a node has 0 outgoing connections, it is likely an Output. For a tree, we can tell if it is a leaf or a vertex based on it’s nunmber of children. However, when building either a graph or tree, we usually want to specify which type of node we want to create. Thus, we typically use this enum more for writing (building nodes) rather than reading (traversing nodes).
See the GraphNode and TreeNode implementations for more details or rules around how this is handled.
Because of this, the NodeType enum is a soft identification, and should be used as a hint rather than a strict rule.
The node_type method in the Node trait has guards around it within the GraphNode
and TreeNode implementations which handle this ambiguity and provide a
more accurate node type when traversing the graph or tree. All that being
said, it is a very very rare case where the node_type method would return a different value than what is
specified in the NodeType enum - the only way this is possible is if the NodeType isn’t supplied to
the node during creation.
Within each node (GraphNode or TreeNode), the NodeType is used to determine the validity of the
node given the value it holds.
Variants§
Input
Input types are only used within graph structrues and are
the starting point for data flow within the graph.
Output
Output types are only used within graph structrues and are
the endpoint for data flow within the graph.
Vertex
Vertex types are used within both graph and tree structures
to represent nodes that must have incoming (or parent) connections and
outgoing connections (or children). This is a general purpose node type and
is likely the type you think of when thinking of a generic node.
Edge
Edge types are only used within graph structures and represent
nodes that have a single incoming connection and n outgoing connections.
This is how we represent weights or other single-input nodes within a graph.
Leaf
Leaf types are used within tree structures to represent nodes
that have no children. They are the endpoint (or output) of the tree structure.
We use Leaf instead of output to avoid confusion and keep terminology consistent.
Root
Root types are used within tree structures to represent the
starting point of the tree. They are the first node in the tree structure and must
have 0 parents.
Trait Implementations§
impl Copy for NodeType
impl Eq for NodeType
Source§impl<T> Factory<NodeType, T> for NodeStore<T>
impl<T> Factory<NodeType, T> for NodeStore<T>
fn new_instance(&self, input: NodeType) -> T
Source§impl Ord for NodeType
impl Ord for NodeType
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for NodeType
impl PartialOrd for NodeType
impl StructuralPartialEq for NodeType
Auto Trait Implementations§
impl Freeze for NodeType
impl RefUnwindSafe for NodeType
impl Send for NodeType
impl Sync for NodeType
impl Unpin for NodeType
impl UnsafeUnpin for NodeType
impl UnwindSafe for NodeType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.