Golang index.suffixarray.FindAllIndex() function example
package index/suffixarray
Golang index.suffixarray.FindAllIndex() function usage example
package main
import (
"fmt"
"index/suffixarray"
"os"
"regexp"
"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))
// list all with taste
match, err := regexp.Compile("\x00tas[^\x00]*")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
result := index.FindAllIndex(match, -1) // <------- here!
// -1 = list all
// see http://golang.org/pkg/index/suffixarray/#Index.FindAllIndex
for _, val := range result {
start, end := val[0], val[1]
fmt.Println(strByte[start+1 : end])
}
}
Reference :
Advertisement
Something interesting
Tutorials
+7.7k Golang : Generate human readable password
+7.1k Nginx : How to block user agent ?
+26.3k Golang : Calculate future date with time.Add() function
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+11.6k Golang : Fuzzy string search or approximate string matching example
+5.4k How to check with curl if my website or the asset is gzipped ?
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+10.6k Golang : Flip coin example
+8.1k Golang : How To Use Panic and Recover
+7.9k Golang : Get today's weekday name and calculate target day distance example
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload