# package suffixarray
`import "index/suffixarray"`
suffixarrayb包通過使用內存中的后綴樹實現了對數級時間消耗的子字符串搜索。
用法舉例:
```
// 創建數據的索引
index := suffixarray.New(data)
// 查找切片s
offsets1 := index.Lookup(s, -1) // 返回data中所有s出現的位置
offsets2 := index.Lookup(s, 3) // 返回data中最多3個所有s出現的位置
```
## Index
* [type Index](#Index)
* [func New(data []byte) \*Index](#New)
* [func (x \*Index) Bytes() []byte](#Index.Bytes)
* [func (x \*Index) Read(r io.Reader) error](#Index.Read)
* [func (x \*Index) Write(w io.Writer) error](#Index.Write)
* [func (x \*Index) Lookup(s []byte, n int) (result []int)](#Index.Lookup)
* [func (x \*Index) FindAllIndex(r \*regexp.Regexp, n int) (result [][]int)](#Index.FindAllIndex)
## type [Index](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L28 "View Source")
```
type Index struct {
// 內含隱藏或非導出字段
}
```
Index類型實現了用于快速子字符串搜索的后綴數組。
### func [New](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L35 "View Source")
```
func New(data []byte) *Index
```
使用給出的[]byte數據生成一個\*Index,時間復雜度O(N\*log(N))。
### func (\*Index) [Bytes](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L165 "View Source")
```
func (x *Index) Bytes() []byte
```
返回創建x時提供的[]byte數據,注意不能修改返回值。
### func (\*Index) [Read](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L98 "View Source")
```
func (x *Index) Read(r io.Reader) error
```
從r中讀取一個index寫入x,x不能為nil。
### func (\*Index) [Write](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L137 "View Source")
```
func (x *Index) Write(w io.Writer) error
```
將x中的index寫入w中,x不能為nil。
### func (\*Index) [Lookup](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L190 "View Source")
```
func (x *Index) Lookup(s []byte, n int) (result []int)
```
返回一個未排序的列表,內為s在被索引為index的切片數據中出現的位置。如果n<0,返回全部匹配;如果n==0或s為空,返回nil;否則n為result的最大長度。時間復雜度O(log(N)\*len(s) + len(result)),其中N是被索引的數據的大小。
### func (\*Index) [FindAllIndex](https://github.com/golang/go/blob/master/src/index/suffixarray/suffixarray.go#L212 "View Source")
```
func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int)
```
返回一個正則表達式r的不重疊的匹配的經過排序的列表,一個匹配表示為一對指定了匹配結果的切片的索引(相對于x.Bytes())。如果n<0,返回全部匹配;如果n==0或匹配失敗,返回nil;否則n為result的最大長度。
- 庫
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe