icentral_cycle/
cycle.rs

1crate::ix!();
2
3/*
4 | But in the last days it shall come to pass, that
5 | the mountain of the house of the LORD shall be
6 | established in the top of the mountains, and it
7 | shall be exalted above the hills; and people shall
8 | flow unto it.
9 |
10 | And many nations shall come, and say, Come, and
11 | let us go up to the mountain of the LORD, and to
12 | the house of the God of Jacob; and he will teach
13 | us of his ways, and we will walk in his paths: for
14 | the law shall go forth of Zion, and the word of
15 | the LORD from Jerusalem.
16 |
17 | And he shall judge among many people, and rebuke
18 | strong nations afar off; and they shall beat their
19 | swords into plowshares, and their spears into
20 | pruninghooks: nation shall not lift up a sword
21 | against nation, neither shall they learn war any
22 | more.
23 |
24 | But they shall sit every man under his vine and
25 | under his fig tree; and none shall make them
26 | afraid: for the mouth of the LORD of hosts hath
27 | spoken it.
28 |
29 | For all people will walk every one in the name of
30 | his god, and we will walk in the name of the LORD
31 | our God for ever and ever.
32 |
33 | -Micah, Ch. 4
34 */
35#[derive(Clone,Debug)]
36pub struct Cycle {
37    edges: Vec<Edge>,
38}
39
40impl NumEdges for Cycle {
41
42    fn num_edges(&self) -> usize {
43        self.edges.len()
44    }
45}
46
47impl std::ops::Index<usize> for Cycle {
48
49    type Output = Edge;
50
51    fn index(&self, idx: usize) -> &Self::Output {
52        &self.edges[idx]
53    }
54}
55
56/**
57  | minimum cycle basis for a graph is a set
58  | of cycles the representation is a vector
59  | of edge lists
60  |
61  */
62#[derive(Debug)]
63pub struct MinimumCycleBasis {
64    cycle_vec: Vec<Cycle>,
65}
66
67impl CreateEmpty for MinimumCycleBasis {
68
69    fn empty() -> Self {
70        Self {
71            cycle_vec: vec![]
72        }
73    }
74}
75
76impl MinimumCycleBasis {
77
78    pub fn cycles(&self) -> &Vec<Cycle> {
79        &self.cycle_vec
80    }
81
82    pub fn num_cycles(&self) -> usize {
83        self.cycle_vec.len()
84    }
85
86    pub fn cycle(&self, idx: NodeId) -> &Cycle {
87        &self.cycle_vec[idx.val()]
88    }
89}