index/suffixarray

Guided tour · Misc · pkg.go.dev →

Substring index backed by a suffix array. Fast repeated lookups into a single large corpus.

Usage

New + Lookup + FindAllIndex

data := []byte("banana bandana")
idx := suffixarray.New(data)
positions := idx.Lookup([]byte("an"), -1)
fmt.Println(positions) // offsets of all "an"

re := regexp.MustCompile("ban.")
ranges := idx.FindAllIndex(re, -1)