index/suffixarray 字典树

最后更新于:2022-04-02 02:42:43

[TOC] ## 语法 ``` type Index func New(data []byte) *Index func (x *Index) Bytes() []byte func (x *Index) Read(r io.Reader) error func (x *Index) Write(w io.Writer) error func (x *Index) Lookup(s []byte, n int) (result []int) func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int) ``` ## 示例 ``` index := suffixarray.New([]byte("abc abc abc")) offsets := index.Lookup([]byte("bc"), -1) fmt.Printf("%+v\n", offsets) // [9 5 1] compile := regexp.MustCompile("bc") allIndex := index.FindAllIndex(compile, -1) fmt.Printf("%+v\n", allIndex) // [[1 3] [5 7] [9 11]] ```
';