Skip to content

Commit

Permalink
fix: 单字匹配模式选重错误
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Mar 14, 2024
1 parent 730750c commit 1cbe555
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions pkg/matcher/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,28 @@ import (
"unicode/utf8"
)

type codePos struct {
code string
pos int
}

type Single struct {
dict map[rune]*struct {
code string
pos int
}
dict map[rune]*codePos
}

func NewSingle() *Single {
s := new(Single)
s.dict = make(map[rune]*struct {
code string
pos int
}, 1024)
s.dict = make(map[rune]*codePos, 1024)
return s
}

func (s *Single) Insert(word, code string, pos int) {
char, _ := utf8.DecodeRuneInString(word)
cp, ok := s.dict[char]
if ok {
if len(cp.code) < len(code) {
// 同一个字取码长较短的
s.dict[char].pos = pos
if _, ok := s.dict[char]; !ok {
s.dict[char] = &codePos{
code: code,
pos: pos,
}
return
}
s.dict[char] = &struct {
code string
pos int
}{
code: code,
pos: pos,
}
}

Expand Down

0 comments on commit 1cbe555

Please sign in to comment.