strongly_connected_components/internal/
scc.rs

1use crate::internal::node::Node;
2
3/// Represents a single
4/// [Strongly Connected Component](https://en.wikipedia.org/wiki/Strongly_connected_component)
5/// (SCC) of a [`Graph`](crate::Graph).
6pub struct Scc {
7    pub(super) id: usize,
8    pub(super) nodes: Vec<Node>,
9}
10
11#[allow(clippy::len_without_is_empty)]
12impl Scc {
13    /// Returns the number of [`Node`]s in this SCC.
14    pub fn len(&self) -> usize {
15        self.nodes.len()
16    }
17
18    /// Returns an iterator over all nodes belonging to this SCC.
19    /// The nodes are returned in no particular order.
20    pub fn iter_nodes(&self) -> impl Iterator<Item = Node> {
21        self.nodes.iter().copied()
22    }
23}
24
25impl std::fmt::Debug for Scc {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(f, "Scc{:?}", self.nodes)
28    }
29}
30
31impl std::cmp::PartialEq for Scc {
32    fn eq(&self, other: &Self) -> bool {
33        self.id == other.id
34    }
35}
36
37impl std::cmp::Eq for Scc {}
38
39impl std::hash::Hash for Scc {
40    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
41        self.id.hash(state);
42    }
43}