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
+16.8k Golang : Get own process identifier
+11.6k Android Studio : Create custom icons for your application example
+8.2k Golang : Metaprogramming example of wrapping a function
+11k Golang : Create S3 bucket with official aws-sdk-go package
+10.4k Golang : Generate random integer or float number
+16.7k Golang : Gzip file example
+7.1k Golang : Get Alexa ranking data example
+12.1k Golang : md5 hash of a string
+19.2k Golang : Execute shell command
+17.1k Golang : XML to JSON example
+7.2k Golang : Check if one string(rune) is permutation of another string(rune)
+11.5k Golang : Change date format to yyyy-mm-dd