| 1 |
package build |
| 2 |
|
| 3 |
import "strconv" |
| 4 |
|
| 5 |
s. |
| 6 |
|
| 7 |
|
| 8 |
func Hyper(n int) *Virtual { |
| 9 |
switch { |
| 10 |
case n < 0: |
| 11 |
return nil |
| 12 |
case n == 0: |
| 13 |
return singleton() |
| 14 |
case n == 1: |
| 15 |
return line(2) |
| 16 |
case n > bitsPerWord-2: |
| 17 |
panic("n=" + strconv.Itoa(n) + " too big; max=" + strconv.Itoa(bitsPerWord-2)) |
| 18 |
} |
| 19 |
|
| 20 |
res := generic0(1<<uint(n), func(v, w int) (edge bool) { |
| 21 |
d := v ^ w |
| 22 |
return d&-d == d |
| 23 |
}) |
| 24 |
|
| 25 |
res.degree = func(v int) (deg int) { |
| 26 |
return n |
| 27 |
} |
| 28 |
|
| 29 |
res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) { |
| 30 |
if v >= a { |
| 31 |
for b := 1 << uint(n); b > 0; b >>= uint(1) { |
| 32 |
if v&b == 0 { |
| 33 |
continue |
| 34 |
} |
| 35 |
if w := v ^ b; w >= a && do(w, 0) { |
| 36 |
return true |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
for b := 1; b < 1<<uint(n); b <<= uint(1) { |
| 41 |
if v&b != 0 { |
| 42 |
continue |
| 43 |
} |
| 44 |
if w := v ^ b; w >= a && do(w, 0) { |
| 45 |
return true |
| 46 |
} |
| 47 |
} |
| 48 |
return |
| 49 |
} |
| 50 |
return res |
| 51 |
} |