# 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