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
+15.2k Golang : Get timezone offset from date or timestamp
+10.4k Golang : Generate random integer or float number
+8k Findstr command the Grep equivalent for Windows
+12.2k Golang : List running EC2 instances and descriptions
+6.1k Java : Human readable password generator
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+19.8k Golang : Append content to a file
+19.1k Mac OSX : Homebrew and Golang
+4.6k Mac OSX : Get disk partitions' size, type and name
+12.6k Golang : Transform comma separated string to slice example