@@ -81,16 +81,20 @@ func (SW *sortWrapper) Less(i, j int) bool {
81
81
82
82
// Creates an inverted suffix from a dictionary of byte arrays, mapping data, and a string->[]byte converter
83
83
func New (Words , Results []string , Data []interface {}, Converter func (string ) []byte ) * InvertedSuffix {
84
- WordIndex := make ([]int , 0 , len (Words ))
85
- SuffixIndex := make ([]int , 0 , len (Words ))
86
- NewWords := make ([][]byte , 0 , len (Words ))
84
+ CharCount := 0
85
+ NewWords := make ([][]byte , len (Words ))
87
86
for i , Word := range Words {
88
- word := Converter (Word )
89
- for j := 0 ; j < len (word ); j ++ {
87
+ NewWord := Converter (Word )
88
+ NewWords [i ] = NewWord
89
+ CharCount += len (NewWord )
90
+ }
91
+ WordIndex := make ([]int , 0 , CharCount )
92
+ SuffixIndex := make ([]int , 0 , CharCount )
93
+ for i , NewWord := range NewWords {
94
+ for j := 0 ; j < len (NewWord ); j ++ {
90
95
WordIndex = append (WordIndex , i )
91
96
SuffixIndex = append (SuffixIndex , j )
92
97
}
93
- NewWords = append (NewWords , word )
94
98
}
95
99
sort .Sort (& sortWrapper {WordIndex , SuffixIndex , NewWords })
96
100
Suffixes := & InvertedSuffix {WordIndex , SuffixIndex , NewWords , Results , Data , Converter }
0 commit comments