...
1
2
3
4
5 package lcs
6
7 import (
8 "fmt"
9 )
10
11
12
13 type label struct {
14 vec [][]int
15 }
16
17
18 const debug = false
19
20
21
22 func checkDK(D, k int) {
23 if k >= -D && k <= D && (D+k)%2 == 0 {
24 return
25 }
26 panic(fmt.Sprintf("out of range, d=%d,k=%d", D, k))
27 }
28
29 func (t *label) set(D, k, x int) {
30 if debug {
31 checkDK(D, k)
32 }
33 for len(t.vec) <= D {
34 t.vec = append(t.vec, nil)
35 }
36 if t.vec[D] == nil {
37 t.vec[D] = make([]int, D+1)
38 }
39 t.vec[D][(D+k)/2] = x
40 }
41
42 func (t *label) get(d, k int) int {
43 if debug {
44 checkDK(d, k)
45 }
46 return int(t.vec[d][(d+k)/2])
47 }
48
49 func newtriang(limit int) label {
50 if limit < 100 {
51
52 return label{vec: make([][]int, limit)}
53 }
54 return label{}
55 }
56
View as plain text