-
Notifications
You must be signed in to change notification settings - Fork 0
/
im.go
67 lines (58 loc) · 1023 Bytes
/
im.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
type imData struct {
c []rune
curP int // P is x
length int
t *node
ts [][]*node
}
func newImData(length int) *imData {
return &imData{
c: make([]rune, length),
curP: 0,
length: length,
t: newT(),
ts: make([][]*node, length),
}
}
func (id *imData) full() bool {
return id.curP == id.length
}
func (id *imData) empty() bool {
return id.curP == 0
}
func (id *imData) put(r rune) {
if id.full() {
return
}
id.c[id.curP] = r
if id.empty() {
id.ts[id.curP] = searchT0(id.t, r)
} else {
id.ts[id.curP] = searchT(id.ts[id.curP-1], r)
}
id.curP++
}
func (id *imData) kj() []string {
if id.empty() {
return nil
}
var ret []string
for _, n := range id.ts[id.curP-1] {
ret = append(ret, n.kj()...)
}
return ret
}
func (id *imData) bs() {
if id.empty() {
return
}
id.curP--
id.ts[id.curP] = nil
}
func subjectIm(r rune) bool {
return ('a' <= r && r <= 'z') || r == wc
}
func subjectSel(r rune) bool {
return '1' <= r && r <= '9'
}