suffixarray

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Index

type Index struct {
	// contains filtered or unexported fields
}

Indexは高速な部分文字列検索のための接尾辞配列を実装しています。

func New

func New(data []byte) *Index

Newはデータのために新しい Index を作成します。 Index の作成時間はO(N)であり、Nはdataの長さです。

func (*Index) Bytes

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

Bytes はインデックスが作成されたデータを返します。 このデータは変更してはいけません。

func (*Index) FindAllIndex

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

FindAllIndexは正規表現rの非重複マッチのソートされたリストを返します。 マッチは、x.Bytes()の一致するスライスを指定するインデックスのペアです。 nが0未満の場合、すべてのマッチが連続して返されます。 そうでない場合、最大でnマッチが返される可能性がありますが、連続しているとは限りません。 マッチがない場合、またはn == 0の場合は、結果はnilです。

func (*Index) Lookup

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

Lookupは、バイト文字列sがインデックス付きデータに出現する最大n箇所のインデックスの非ソートリストを返します。n < 0の場合、すべての出現箇所が返されます。 sが空である、sが見つからない、またはn == 0の場合、結果はnilです。 ルックアップ時間はO(log(N)*len(s) + len(result))であり、Nはインデックス付きデータのサイズです。

Example
package main

import (
	"github.com/shogo82148/std/fmt"
	"github.com/shogo82148/std/index/suffixarray"
)

func main() {
	index := suffixarray.New([]byte("banana"))
	offsets := index.Lookup([]byte("ana"), -1)
	for _, off := range offsets {
		fmt.Println(off)
	}

}
Output:

1
3

func (*Index) Read

func (x *Index) Read(r io.Reader) error

Readはrからインデックスをxに読み込む。xはnilであってはならない。

func (*Index) Write

func (x *Index) Write(w io.Writer) error

Writeはインデックスxをwに書き込みます。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL