suffixarray
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package suffixarray implements substring search in logarithmic time usingan in-memory suffix array.
Example use:
// create index for some dataindex := suffixarray.New(data)// lookup byte slice soffsets1 := index.Lookup(s, -1) // the list of all indices where s occurs in dataoffsets2 := index.Lookup(s, 3) // the list of at most 3 indices where s occurs in data
Index¶
Examples¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeIndex¶
type Index struct {// contains filtered or unexported fields}
Index implements a suffix array for fast substring search.
func (*Index)FindAllIndex¶
FindAllIndex returns a sorted list of non-overlapping matches of theregular expression r, where a match is a pair of indices specifyingthe matched slice of x.Bytes(). If n < 0, all matches are returnedin successive order. Otherwise, at most n matches are returned andthey may not be successive. The result is nil if there are no matches,or if n == 0.
func (*Index)Lookup¶
Lookup returns an unsorted list of at most n indices where the byte string soccurs in the indexed data. If n < 0, all occurrences are returned.The result is nil if s is empty, s is not found, or n == 0.Lookup time is O(log(N)*len(s) + len(result)) where N is thesize of the indexed data.
Example¶
package mainimport ("fmt""index/suffixarray")func main() {index := suffixarray.New([]byte("banana"))offsets := index.Lookup([]byte("ana"), -1)for _, off := range offsets {fmt.Println(off)}}
Output:13