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.5k Golang : Check if a string contains multiple sub-strings in []string?
+19.9k Golang : How to get time from unix nano example
+14.6k Golang : Execute function at intervals or after some delay
+8.2k Golang : HttpRouter multiplexer routing example
+9.6k Golang : Quadratic example
+11k Golang : Create S3 bucket with official aws-sdk-go package
+5.4k Golang : Return multiple values from function
+51.9k Golang : How to get time in milliseconds?
+10.1k Golang : Identifying Golang HTTP client request
+7.5k Golang : Shuffle strings array
+12.5k Golang : Forwarding a local port to a remote server example
+32.1k Golang : Validate email address with regular expression