Skip to content

Commit 94b330b

Browse files
committed
Fix some remaining problems of issue #6
1 parent b9d9caa commit 94b330b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ferret.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,20 @@ func (SW *sortWrapper) Less(i, j int) bool {
8181

8282
// Creates an inverted suffix from a dictionary of byte arrays, mapping data, and a string->[]byte converter
8383
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))
8786
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++ {
9095
WordIndex = append(WordIndex, i)
9196
SuffixIndex = append(SuffixIndex, j)
9297
}
93-
NewWords = append(NewWords, word)
9498
}
9599
sort.Sort(&sortWrapper{WordIndex, SuffixIndex, NewWords})
96100
Suffixes := &InvertedSuffix{WordIndex, SuffixIndex, NewWords, Results, Data, Converter}

0 commit comments

Comments
 (0)