digraph_rs/
analyzer.rs

1use crate::analyzer::dijkstra::DijkstraPath;
2use crate::DiGraph;
3use graphviz_rust::dot_structures::Node;
4use std::hash::Hash;
5
6pub mod astar;
7pub mod dijkstra;
8pub mod dom;
9pub mod fs;
10pub mod min_weight;
11pub mod visit;
12
13enum SearchRes {
14    Next,
15    Find,
16    Stop,
17    Skip,
18}
19
20#[derive(Debug)]
21pub struct GraphAnalyzer<'a, NodeId, NL, EL>
22where
23    NodeId: Eq + Hash,
24{
25    pub(crate) graph: &'a DiGraph<NodeId, NL, EL>,
26}
27
28impl<'a, NodeId, NL, EL> GraphAnalyzer<'a, NodeId, NL, EL>
29where
30    NodeId: Eq + Hash,
31    NL: PartialEq,
32{
33    pub fn node_by_id(&self, id: &NodeId) -> Option<&NL> {
34        self.graph.nodes.get(id)
35    }
36    pub fn first_node_by_payload(&self, payload: &NL) -> Option<&NL> {
37        self.graph.nodes.values().find(|v| *v == payload)
38    }
39    pub fn node(&self, id: &NodeId, payload: &NL) -> Option<&NL> {
40        self.graph.nodes.get(id).filter(|v| *v == payload)
41    }
42}
43
44impl<'a, NodeId, NL, EL> GraphAnalyzer<'a, NodeId, NL, EL>
45where
46    NodeId: Eq + Hash,
47{
48    pub fn edge(&self, from: &NodeId, to: &NodeId) -> Option<&EL> {
49        self.graph.edges.get(from).and_then(|tos| tos.get(to))
50    }
51}