Debian Codegraph @

build/cycle.go

raw symbols SCIP
1 package build
2
3 // Cycle returns a virtual cycle graph with n vertices and
4 // the edges {0, 1}, {1, 2}, {2, 3},... , {n-1, 0}.
5 func Cycle(n int) *Virtual {
6 switch {
7 case n < 0:
8 return nil
9 case n == 0:
10 return null
11 case n == 1:
12 return singleton()
13 case n == 2:
14 return edge()
15 }
16
17 g := generic0(n, func(v, w int) (edge bool) {
18 switch v - w {
19 case 1 - n, -1, 1, n - 1:
20 edge = true
21 }
22 return
23 })
24
25 // Precondition : n ≥ 3.
26 g.degree = func(v int) int { return 2 }
27
28 // Precondition : n ≥ 3.
29 g.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
30 var w [2]int
31 switch v {
32 case 0:
33 w = [2]int{1, n - 1}
34 case n - 1:
35 w = [2]int{0, n - 2}
36 default:
37 w = [2]int{v - 1, v + 1}
38 }
39 for _, w := range w {
40 if w >= a && do(w, 0) {
41 return true
42 }
43 }
44 return
45 }
46 return g
47 }