GoPLS Viewer

Home|gopls/internal/diff/lcs/labels.go
1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package lcs
6
7import (
8    "fmt"
9)
10
11//  For each D, vec[D] has length D+1,
12// and the label for (D, k) is stored in vec[D][(D+k)/2].
13type label struct {
14    vec [][]int
15}
16
17// Temporary checking DO NOT COMMIT true TO PRODUCTION CODE
18const debug = false
19
20// debugging. check that the (d,k) pair is valid
21// (that is, -d<=k<=d and d+k even)
22func checkDK(Dk 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"Dk))
27}
28
29func (t *labelset(Dkx int) {
30    if debug {
31        checkDK(Dk)
32    }
33    for len(t.vec) <= D {
34        t.vec = append(t.vecnil)
35    }
36    if t.vec[D] == nil {
37        t.vec[D] = make([]intD+1)
38    }
39    t.vec[D][(D+k)/2] = x // known that D+k is even
40}
41
42func (t *labelget(dk intint {
43    if debug {
44        checkDK(dk)
45    }
46    return int(t.vec[d][(d+k)/2])
47}
48
49func newtriang(limit intlabel {
50    if limit < 100 {
51        // Preallocate if limit is not large.
52        return label{vecmake([][]intlimit)}
53    }
54    return label{}
55}
56
MembersX
fmt
debug
label.set.k
label.get.k
newtriang
newtriang.limit
checkDK
checkDK.k
label.set
label.set.D
label.set.x
label.get
label
label.vec
checkDK.D
label.set.t
label.get.t
label.get.d
Members
X