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
+5.6k Python : Print unicode escape characters and string
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+9.4k Golang : How to protect your source code from client, hosting company or hacker?
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+25k Golang : Create PDF file from HTML file
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+17.6k Golang : delete and modify XML file content
+8.6k Golang : Set or add headers for many or different handlers
+17.1k Golang : Capture stdout of a child process and act according to the result
+8.1k Golang : Multiplexer with net/http and map
+22.6k Generate checksum for a file in Go
+5k Python : Convert(cast) bytes to string example