pub struct Graph { /* private fields */ }Expand description
Represents the graph on which SCC decomposition will be done.
Consists of Nodes, connected by directed edges.
let mut graph = Graph::new();
let v0 = graph.new_node();
let v1 = graph.new_node();
let v2 = graph.new_node();
let v3 = graph.new_node();
graph.new_edge(v0, v1);
graph.new_edge(v1, v3);
graph.new_edge(v1, v1);
// Graph looks like this:
// ┌───┐ ┌───┐ ┌───┐ ┌───┐
// │ 0 ├─►│ 1 ├─►│ 3 │ │ 2 │
// └───┘ └▲─┬┘ └───┘ └───┘
// └─┘Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty graph with no nodes and no edges.
Nodes can be added by calling Graph::new_node.
Edges can be added by calling Graph::new_edge.
Sourcepub fn new_node(&mut self) -> Node
pub fn new_node(&mut self) -> Node
Creates a new node of the graph with no incoming/outgoing edges.
Edges can be added by calling Graph::new_edge.
Sourcepub fn new_edge(&mut self, from: Node, to: Node)
pub fn new_edge(&mut self, from: Node, to: Node)
Creates a new directed edge between two nodes.
Sourcepub fn find_sccs(&self) -> SccDecomposition
pub fn find_sccs(&self) -> SccDecomposition
Computes the Strongly Connected Components decomposition of this graph. Uses Tarjan’s algorithm which runs in O(|N| + |E|) time and uses O(|N| + |E|) memory.
Sourcepub fn iter_nodes(&self) -> impl Iterator<Item = Node>
pub fn iter_nodes(&self) -> impl Iterator<Item = Node>
Iterates over all nodes that belong to this graph, in no particular order.
Sourcepub fn iter_successors(&self, node: Node) -> impl Iterator<Item = Node>
pub fn iter_successors(&self, node: Node) -> impl Iterator<Item = Node>
Iterates over all successors of the given node, in no particular order.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnwindSafe for Graph
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
Mutably borrows from an owned value. Read more