1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::omnitigs::{NodeCentricUnivocalExtensionAlgorithm, UnivocalExtensionAlgorithm};
use crate::walks::{EdgeOmnitigLikeExt, NodeOmnitigLikeExt};
use std::borrow::Borrow;
use traitgraph::interface::StaticGraph;

/// Computes the univocal extension of a walk assuming the graph is strongly connected.
/// Might enter an infinite loop if the graph is not strongly connected.
pub struct SccUnivocalExtensionStrategy;

impl<Graph: StaticGraph, ResultWalk: From<Vec<Graph::EdgeIndex>>>
    UnivocalExtensionAlgorithm<Graph, ResultWalk> for SccUnivocalExtensionStrategy
{
    fn compute_univocal_extension(graph: &Graph, walk: &[Graph::EdgeIndex]) -> ResultWalk {
        EdgeOmnitigLikeExt::compute_univocal_extension(walk.borrow(), graph)
    }
}

/// Computes the univocal extension of a walk assuming the graph is not strongly connected.
pub struct NonSccUnivocalExtensionStrategy;

impl<Graph: StaticGraph, ResultWalk: From<Vec<Graph::EdgeIndex>>>
    UnivocalExtensionAlgorithm<Graph, ResultWalk> for NonSccUnivocalExtensionStrategy
{
    fn compute_univocal_extension(graph: &Graph, walk: &[Graph::EdgeIndex]) -> ResultWalk {
        EdgeOmnitigLikeExt::compute_univocal_extension_non_scc(walk.borrow(), graph)
    }
}

/// Computes the univocal extension of a walk assuming the graph is strongly connected.
/// Might enter an infinite loop if the graph is not strongly connected.
pub struct SccNodeCentricUnivocalExtensionStrategy;

impl<Graph: StaticGraph, ResultWalk: From<Vec<Graph::NodeIndex>>>
    NodeCentricUnivocalExtensionAlgorithm<Graph, ResultWalk>
    for SccNodeCentricUnivocalExtensionStrategy
{
    fn compute_univocal_extension(graph: &Graph, walk: &[Graph::NodeIndex]) -> ResultWalk {
        NodeOmnitigLikeExt::compute_univocal_extension(walk.borrow(), graph)
    }
}

/// Computes the univocal extension of a walk assuming the graph is not strongly connected.
pub struct NonSccNodeCentricUnivocalExtensionStrategy;

impl<Graph: StaticGraph, ResultWalk: From<Vec<Graph::NodeIndex>>>
    NodeCentricUnivocalExtensionAlgorithm<Graph, ResultWalk>
    for NonSccNodeCentricUnivocalExtensionStrategy
{
    fn compute_univocal_extension(graph: &Graph, walk: &[Graph::NodeIndex]) -> ResultWalk {
        NodeOmnitigLikeExt::compute_univocal_extension_non_scc(walk.borrow(), graph)
    }
}