Golang index.suffixarray.New() function example
package index/suffixarray
Golang index.suffixarray.New() function usage example
package main
import (
"fmt"
"index/suffixarray"
"regexp"
"os"
"strings"
)
func main() {
str := []string{"yum", "tasty", "taste good", "delicious", "sumptuous", "lavish", "palatable", "pleasant"}
strByte := "\x00" + strings.Join(str, "\x00")
index := suffixarray.New([]byte(strByte)) // <--------- here
// list all with taste
match, err := regexp.Compile("\x00tas[^\x00]*")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
result := index.FindAllIndex(match, -1)
for _, val := range result {
start, end := val[0], val[1]
fmt.Println(strByte[start+1:end])
}
}
Reference :
Advertisement
Something interesting
Tutorials
+14.5k Golang : How to determine if user agent is a mobile device example
+10.8k Golang : Command line file upload program to server example
+9.6k Golang : Validate IPv6 example
+46.2k Golang : Read tab delimited file with encoding/csv package
+11.5k Golang : Change date format to yyyy-mm-dd
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+26.8k Golang : Find files by extension
+10k Golang : Convert octal value to string to deal with leading zero problem
+16.3k Golang :Trim white spaces from a string
+11.1k Golang : Roll the dice example
+7.3k Golang : alternative to os.Exit() function
+10.7k Golang : Get currencies exchange rates example