MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / NewDoubleArray

Function NewDoubleArray

utilities/trie.go:18–38  ·  view source on GitHub ↗

NewDoubleArray builds a DoubleArray from a set of sequences of strings.

(seqs [][]string)

Source from the content-addressed store, hash-verified

16
17// NewDoubleArray builds a DoubleArray from a set of sequences of strings.
18func NewDoubleArray(seqs [][]string) *DoubleArray {
19 da := &DoubleArray{Encoding: make(map[string]int)}
20 if len(seqs) == 0 {
21 return da
22 }
23
24 encoded := registerTokens(da, seqs)
25 sort.Sort(byLex(encoded))
26
27 root := node{row: -1, col: -1, left: 0, right: len(encoded)}
28 addSeqs(da, encoded, 0, root)
29
30 for i := len(da.Base); i > 0; i-- {
31 if da.Check[i-1] != 0 {
32 da.Base = da.Base[:i]
33 da.Check = da.Check[:i]
34 break
35 }
36 }
37 return da
38}
39
40func registerTokens(da *DoubleArray, seqs [][]string) [][]int {
41 var result [][]int

Calls 3

registerTokensFunction · 0.85
byLexTypeAlias · 0.85
addSeqsFunction · 0.85