graph_types/vertexes/
mod.rs

1pub mod get_iter;
2pub mod indexed;
3pub mod mut_iter;
4pub mod node_range_visitor;
5pub mod node_slice_visitor;
6
7use crate::GraphEngine;
8use std::{
9    any::type_name,
10    fmt::{Debug, Formatter},
11    ops::{Bound, Range, RangeBounds},
12};
13
14/// used to determine the direction of an edge
15pub type NodeID = usize;
16
17/// used to determine the direction of an edge
18#[repr(u8)]
19#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
20pub enum NodeNeighborFilter {
21    Both = 0,
22    /// used to determine the direction of an edge
23    InComing = 1,
24    /// used to determine the direction of an edge
25    OutGoing = 2,
26}
27
28/// used to determine the direction of an edge
29#[repr(u8)]
30#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
31pub enum VisitOrder {
32    /// used to determine the direction of an edge
33    Topological = 0,
34    /// used to determine the direction of an edge
35    DepthFirst = 1,
36    /// used to determine the direction of an edge
37    BreadthFirst = 2,
38    /// used to determine the direction of an edge
39    PreOrder = 3,
40    /// used to determine the direction of an edge
41    PostOrder = 4,
42}
43
44#[derive(Copy, Clone, Debug)]
45pub enum NodeDegree {
46    Directed {
47        /// used to determine the direction of an edge
48        in_coming: usize,
49        /// used to determine the direction of an edge
50        out_going: usize,
51    },
52    Undirected {
53        /// used to determine the direction of an edge
54        total: usize,
55    },
56}
57
58impl NodeDegree {
59    /// used to determine the direction of an edge
60    pub fn total(&self) -> usize {
61        match self {
62            NodeDegree::Directed { in_coming, out_going } => in_coming + out_going,
63            NodeDegree::Undirected { total } => *total,
64        }
65    }
66}
67
68/// Represents a node in a graph
69///
70/// ```
71/// use graph_theory::GraphEngine;
72/// ```
73pub trait Node {
74    /// The type of the node's index
75    type Name: AsRef<str>;
76    /// The index of the node, all kinds of nodes must have an index
77    ///
78    /// # Examples
79    ///
80    /// ```
81    /// use graph_theory::GraphEngine;
82    /// ```
83    fn index(&self) -> NodeID;
84    /// The weight of the node, only weighted graph nodes has a weight
85    ///
86    /// # Examples
87    ///
88    /// ```
89    /// use graph_theory::GraphEngine;
90    /// ```
91    fn name(&self) -> Self::Name;
92}