-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathedge_weighted_directed_cycle.go
58 lines (47 loc) · 1.23 KB
/
edge_weighted_directed_cycle.go
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
53
54
55
56
57
58
package algs4
// EdgeWeightedDirectedCycle for EdgeWeightedDigrapy
// Note: this is file is just placeholder, see detail algorithm in directed_cycle.go
type EdgeWeightedDirectedCycle struct {
marked []bool
edgeTo []int
cycle []*DirectedEdge
onStack []bool
}
// NewEdgeWeightedDirectedCycle ...
func NewEdgeWeightedDirectedCycle(g *EdgeWeightedDigraph) *EdgeWeightedDirectedCycle {
marked := make([]bool, g.V())
edgeTo := make([]int, g.V())
onStack := make([]bool, g.V())
c := &EdgeWeightedDirectedCycle{marked: marked, edgeTo: edgeTo, onStack: onStack}
if c.hasSelfLoop(g) {
return c
}
if c.hasParallelEdges(g) {
return c
}
for v := 0; v < g.V(); v++ {
if !c.marked[v] {
c.Dfs(g, -1, v)
}
}
return c
}
// hasSelfLoop ...
func (c *EdgeWeightedDirectedCycle) hasSelfLoop(g *EdgeWeightedDigraph) bool {
return false
}
// hasParallelEdges ...
func (c *EdgeWeightedDirectedCycle) hasParallelEdges(g *EdgeWeightedDigraph) bool {
return false
}
// Dfs ...
func (c *EdgeWeightedDirectedCycle) Dfs(g *EdgeWeightedDigraph, u, v int) {
}
// HasCycle ...
func (c *EdgeWeightedDirectedCycle) HasCycle() bool {
return c.cycle != nil
}
// Cycle ...
func (c *EdgeWeightedDirectedCycle) Cycle() []*DirectedEdge {
return c.cycle
}