File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -147,25 +147,19 @@ func (m *AcModel) buildFailPointers() {
147
147
148
148
func (m * AcModel ) Listen (addChan , delChan <- chan string ) {
149
149
go func () {
150
- var words []string
151
-
152
150
for word := range addChan {
153
- words = append ( words , word )
151
+ m . addWord ( word )
154
152
if len (addChan ) == 0 {
155
- m .AddWords (words ... )
156
- word = word [:0 ]
153
+ m .buildFailPointers ()
157
154
}
158
155
}
159
156
}()
160
157
161
158
go func () {
162
- var words []string
163
-
164
159
for word := range delChan {
165
- words = append ( words , word )
160
+ m . delWord ( word )
166
161
if len (delChan ) == 0 {
167
- m .DelWords (words ... )
168
- word = word [:0 ]
162
+ m .buildFailPointers ()
169
163
}
170
164
}
171
165
}()
Original file line number Diff line number Diff line change @@ -3,11 +3,12 @@ package store
3
3
import (
4
4
"bufio"
5
5
"errors"
6
- "github.com/imroc/req/v3"
7
- cmap "github.com/orcaman/concurrent-map/v2"
8
6
"io"
9
7
"net/http"
10
8
"os"
9
+
10
+ "github.com/imroc/req/v3"
11
+ cmap "github.com/orcaman/concurrent-map/v2"
11
12
)
12
13
13
14
type MemoryModel struct {
@@ -19,8 +20,8 @@ type MemoryModel struct {
19
20
func NewMemoryModel () * MemoryModel {
20
21
return & MemoryModel {
21
22
store : cmap .New [struct {}](),
22
- addChan : make (chan string ),
23
- delChan : make (chan string ),
23
+ addChan : make (chan string , 1000 ),
24
+ delChan : make (chan string , 1000 ),
24
25
}
25
26
}
26
27
You can’t perform that action at this time.
0 commit comments