-
Notifications
You must be signed in to change notification settings - Fork 2
/
utility.go
44 lines (35 loc) · 999 Bytes
/
utility.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
// Copyright 2016 David Lavieri. All rights reserved.
// Use of this source code is governed by a MIT License
// License that can be found in the LICENSE file.
package goradix
import "bytes"
func buildWords(rt *Radix, bs, strip []byte, words chan<- []byte, ww bool) {
var npath []byte
npath = append(bs, rt.Path...)
if len(rt.nodes) > 0 {
if rt.key {
addWord(rt, npath, strip, ww, words)
}
for _, n := range rt.nodes {
buildWords(n, npath, strip, words, ww)
}
} else if rt.key {
addWord(rt, npath, strip, ww, words)
}
}
func addWord(rt *Radix, npath, strip []byte, ww bool, words chan<- []byte) {
if w := bytes.Replace(npath, strip, nil, 1); len(w) > 0 {
if !ww {
words <- w
} else if _, matches, _ := rt.match(strip); matches != len(rt.Path) && ww {
words <- w
}
}
}
func buildWordsWorker(inWords <-chan []byte, outWords chan<- [][]byte) {
var wordSlice [][]byte
for v := range inWords {
wordSlice = append(wordSlice, v)
}
outWords <- wordSlice
}