package suffixarray
Import Path
index/suffixarray (on go.dev)
Dependency Relation
imports 8 packages, and imported by 0 packages
Involved Source Files
sais.go
sais2.go
Package suffixarray implements substring search in logarithmic time using
an in-memory suffix array.
Example use:
// create index for some data
index := suffixarray.New(data)
// lookup byte slice s
offsets1 := index.Lookup(s, -1) // the list of all indices where s occurs in data
offsets2 := index.Lookup(s, 3) // the list of at most 3 indices where s occurs in data
Code Examples
package main
import (
"fmt"
"index/suffixarray"
)
func main() {
index := suffixarray.New([]byte("banana"))
offsets := index.Lookup([]byte("ana"), -1)
for _, off := range offsets {
fmt.Println(off)
}
}
Package-Level Type Names (only one)
Index implements a suffix array for fast substring search.
Bytes returns the data over which the index was created.
It must not be modified.
FindAllIndex returns a sorted list of non-overlapping matches of the
regular expression r, where a match is a pair of indices specifying
the matched slice of x.Bytes(). If n < 0, all matches are returned
in successive order. Otherwise, at most n matches are returned and
they may not be successive. The result is nil if there are no matches,
or if n == 0.
Lookup returns an unsorted list of at most n indices where the byte string s
occurs 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 the
size of the indexed data.
Read reads the index from r into x; x must not be nil.
Write writes the index x to w.
func New(data []byte) *Index
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |