-
Notifications
You must be signed in to change notification settings - Fork 3
/
skip.go
53 lines (45 loc) · 1.72 KB
/
skip.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
package filter
import (
"sort"
)
const sortedSkipList = "\n\r!\"#$%&'()*+-:;=@[]^_{|}~¤§¨°±·×÷ˉΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψω—―‖‘’“”…‰※€℃№ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ←↑→↓∈∏∑√∝∞∠∥∧∨∩∪∫∮∴∵∶∷∽≈≌≠≡≤≥≮≯⊙⊥⌒①②③④⑤⑥⑦⑧⑨⑩⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛─━│┃┄┅┆┇┈┉┊┋┌┍┎┐┑┒┓└┕┖┗┘┙┚┛├┝┞┟┠┡┢┣┤┥┦┧┨┩┪┫┬┭┮┯┰┱┲┳┴┵┶┷┸┹┺┻┼┽┾┿╀╁╂╃╄╅╆╇╈╉╊╋■□▲△◆◇○◎●★☆♀♂、、、。。〃々〈〉《《》》「」『』【【】】〓〔〕〖〗㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩︿!"#&'()+,,-./:;<=>??@[\]_`{|}~ ̄"
func SortedSkipList() string {
return sortedSkipList
}
type Skip struct {
list []rune
}
func (_this *Skip) Set(s string) {
list := []rune(s)
sort.Slice(list, func(i, j int) bool {
return list[i] < list[j]
})
_this.list = list
}
func (_this *Skip) SetSorted(s string) {
list := []rune(s)
_this.list = list
}
func (_this *Skip) ShouldSkip(r rune) bool {
left, right := 0, len(_this.list)
if right == 0 {
return false
}
if r < _this.list[0] || r > _this.list[right-1] {
return false
}
for left < right {
mid := (left + right) >> 1
if _this.list[mid] == r {
return true
} else if _this.list[mid] > r {
right = mid
} else {
left = mid + 1
}
}
return false
}
func (_this *Skip) String() string {
return string(_this.list)
}