Movatterモバイル変換


[0]ホーム

URL:


suffixarray

packagestandard library
go1.25.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:8Imported by:367

Details

Repository

cs.opensource.google/go/go

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.

funcNew

func New(data []byte) *Index

New creates a newIndex for data.Index creation time is O(N) for N = len(data).

func (*Index)Bytes

func (x *Index) Bytes() []byte

Bytes returns the data over which the index was created.It must not be modified.

func (*Index)FindAllIndex

func (x *Index) FindAllIndex(r *regexp.Regexp, nint) (result [][]int)

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

func (x *Index) Lookup(s []byte, nint) (result []int)

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

func (*Index)Read

func (x *Index) Read(rio.Reader)error

Read reads the index from r into x; x must not be nil.

func (*Index)Write

func (x *Index) Write(wio.Writer)error

Write writes the index x to w.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp