Style: format code by gofumpt (#761)

This commit is contained in:
yuhan6665 2021-10-19 12:57:14 -04:00 committed by GitHub
parent d77be80b40
commit e286cdcaa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
111 changed files with 293 additions and 291 deletions

View file

@ -122,7 +122,7 @@ var char2Index = []int{
}
func NewACAutomaton() *ACAutomaton {
var ac = new(ACAutomaton)
ac := new(ACAutomaton)
ac.trie = append(ac.trie, newNode())
ac.fail = append(ac.fail, 0)
ac.exists = append(ac.exists, MatchType{
@ -133,9 +133,9 @@ func NewACAutomaton() *ACAutomaton {
}
func (ac *ACAutomaton) Add(domain string, t Type) {
var node = 0
node := 0
for i := len(domain) - 1; i >= 0; i-- {
var idx = char2Index[domain[i]]
idx := char2Index[domain[i]]
if ac.trie[node][idx].nextNode == 0 {
ac.count++
if len(ac.trie) < ac.count+1 {
@ -163,7 +163,7 @@ func (ac *ACAutomaton) Add(domain string, t Type) {
matchType: Full,
exist: true,
}
var idx = char2Index['.']
idx := char2Index['.']
if ac.trie[node][idx].nextNode == 0 {
ac.count++
if len(ac.trie) < ac.count+1 {
@ -190,18 +190,18 @@ func (ac *ACAutomaton) Add(domain string, t Type) {
}
func (ac *ACAutomaton) Build() {
var queue = list.New()
queue := list.New()
for i := 0; i < validCharCount; i++ {
if ac.trie[0][i].nextNode != 0 {
queue.PushBack(ac.trie[0][i])
}
}
for {
var front = queue.Front()
front := queue.Front()
if front == nil {
break
} else {
var node = front.Value.(Edge).nextNode
node := front.Value.(Edge).nextNode
queue.Remove(front)
for i := 0; i < validCharCount; i++ {
if ac.trie[node][i].nextNode != 0 {
@ -219,13 +219,13 @@ func (ac *ACAutomaton) Build() {
}
func (ac *ACAutomaton) Match(s string) bool {
var node = 0
var fullMatch = true
node := 0
fullMatch := true
// 1. the match string is all through trie edge. FULL MATCH or DOMAIN
// 2. the match string is through a fail edge. NOT FULL MATCH
// 2.1 Through a fail edge, but there exists a valid node. SUBSTR
for i := len(s) - 1; i >= 0; i-- {
var idx = char2Index[s[i]]
idx := char2Index[s[i]]
fullMatch = fullMatch && ac.trie[node][idx].edgeType
node = ac.trie[node][idx].nextNode
switch ac.exists[node].matchType {

View file

@ -102,7 +102,7 @@ func (g *MphMatcherGroup) Build() {
g.level0Mask = len(g.level0) - 1
g.level1 = make([]uint32, nextPow2(keyLen))
g.level1Mask = len(g.level1) - 1
var sparseBuckets = make([][]int, len(g.level0))
sparseBuckets := make([][]int, len(g.level0))
var ruleIdx int
for rule, hash := range *g.ruleMap {
n := int(hash) & g.level0Mask
@ -122,7 +122,7 @@ func (g *MphMatcherGroup) Build() {
occ := make([]bool, len(g.level1))
var tmpOcc []int
for _, bucket := range buckets {
var seed = uint32(0)
seed := uint32(0)
for {
findSeed := true
tmpOcc = tmpOcc[:0]
@ -284,9 +284,11 @@ tail:
h ^= h >> 32
return uintptr(h)
}
func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
}
func readUnaligned32(p unsafe.Pointer) uint32 {
q := (*[4]byte)(p)
return uint32(q[0]) | uint32(q[1])<<8 | uint32(q[2])<<16 | uint32(q[3])<<24
@ -295,6 +297,7 @@ func readUnaligned32(p unsafe.Pointer) uint32 {
func rotl31(x uint64) uint64 {
return (x << 31) | (x >> (64 - 31))
}
func readUnaligned64(p unsafe.Pointer) uint64 {
q := (*[8]byte)(p)
return uint64(q[0]) | uint64(q[1])<<8 | uint64(q[2])<<16 | uint64(q[3])<<24 | uint64(q[4])<<32 | uint64(q[5])<<40 | uint64(q[6])<<48 | uint64(q[7])<<56

View file

@ -143,7 +143,7 @@ func TestACAutomaton(t *testing.T) {
},
}
for _, test := range cases1 {
var ac = NewACAutomaton()
ac := NewACAutomaton()
ac.Add(test.pattern, test.mType)
ac.Build()
if m := ac.Match(test.input); m != test.output {
@ -176,7 +176,7 @@ func TestACAutomaton(t *testing.T) {
mType: Substr,
},
}
var ac = NewACAutomaton()
ac := NewACAutomaton()
for _, test := range cases2Input {
ac.Add(test.pattern, test.mType)
}
@ -239,7 +239,7 @@ func TestACAutomaton(t *testing.T) {
mType: Domain,
},
}
var ac = NewACAutomaton()
ac := NewACAutomaton()
for _, test := range cases3Input {
ac.Add(test.pattern, test.mType)
}