-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_linked.go
More file actions
45 lines (41 loc) · 921 Bytes
/
check_linked.go
File metadata and controls
45 lines (41 loc) · 921 Bytes
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
package law
type checkNode struct {
next *checkNode
check checker
}
func linkCheck(checkers ...checker) *checkNode {
// 将检测链串起来
if len(checkers) == 0 {
return nil
}
cur := &checkNode{check: checkers[0]}
head := &checkNode{next: cur}
for i := 1; i < len(checkers); i++ {
cur.next = &checkNode{check: checkers[i]}
cur = cur.next
}
return head.next
}
func check(cur *checkNode, list []int) (bool, int) {
// 根据检查链进行检查
for cur != nil {
ok, val := cur.check(list)
if ok {
return ok, val
}
cur = cur.next
}
return false, 0
}
func inverseOperation(diff *changeNode, lastVal int) (ok bool, val int) {
// 根据路径节点的类型执行对应逆操作
val, ok = lastVal, true
for diff != nil && diff.pre != nil {
ok, val = invOperationFactor(diff.change_type)(val, (*diff.pre.list)[len(*diff.list)])
if !ok {
return
}
diff = diff.pre
}
return
}