Update Go library to r60.
From-SVN: r178910
This commit is contained in:
parent
5548ca3540
commit
adb0401dac
718 changed files with 58911 additions and 30469 deletions
|
@ -22,21 +22,18 @@ import (
|
|||
"sort"
|
||||
)
|
||||
|
||||
|
||||
// Index implements a suffix array for fast substring search.
|
||||
type Index struct {
|
||||
data []byte
|
||||
sa []int // suffix array for data
|
||||
}
|
||||
|
||||
|
||||
// New creates a new Index for data.
|
||||
// Index creation time is O(N*log(N)) for N = len(data).
|
||||
func New(data []byte) *Index {
|
||||
return &Index{data, qsufsort(data)}
|
||||
}
|
||||
|
||||
|
||||
// Bytes returns the data over which the index was created.
|
||||
// It must not be modified.
|
||||
//
|
||||
|
@ -44,12 +41,10 @@ func (x *Index) Bytes() []byte {
|
|||
return x.data
|
||||
}
|
||||
|
||||
|
||||
func (x *Index) at(i int) []byte {
|
||||
return x.data[x.sa[i]:]
|
||||
}
|
||||
|
||||
|
||||
// lookupAll returns a slice into the matching region of the index.
|
||||
// The runtime is O(log(N)*len(s)).
|
||||
func (x *Index) lookupAll(s []byte) []int {
|
||||
|
@ -61,7 +56,6 @@ func (x *Index) lookupAll(s []byte) []int {
|
|||
return x.sa[i:j]
|
||||
}
|
||||
|
||||
|
||||
// Lookup returns an unsorted list of at most n indices where the byte string s
|
||||
// occurs 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.
|
||||
|
@ -82,7 +76,6 @@ func (x *Index) Lookup(s []byte, n int) (result []int) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
// FindAllIndex returns a sorted list of non-overlapping matches of the
|
||||
// regular expression r, where a match is a pair of indices specifying
|
||||
// the matched slice of x.Bytes(). If n < 0, all matches are returned
|
||||
|
@ -115,7 +108,7 @@ func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int) {
|
|||
if len(indices) == 0 {
|
||||
return
|
||||
}
|
||||
sort.SortInts(indices)
|
||||
sort.Ints(indices)
|
||||
pairs := make([]int, 2*len(indices))
|
||||
result = make([][]int, len(indices))
|
||||
count := 0
|
||||
|
@ -159,7 +152,7 @@ func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int) {
|
|||
if len(indices) == 0 {
|
||||
return
|
||||
}
|
||||
sort.SortInts(indices)
|
||||
sort.Ints(indices)
|
||||
result = result[0:0]
|
||||
prev := 0
|
||||
for _, i := range indices {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue