mirror of
https://github.com/golang/go
synced 2024-11-22 03:54:39 -07:00
suffixarray: cleanup per suggestion from Roger Peppe
R=rsc CC=golang-dev https://golang.org/cl/2213045
This commit is contained in:
parent
ad9042bdfa
commit
3487495eb0
@ -43,9 +43,9 @@ func New(data []byte) *Index {
|
|||||||
for i, _ := range sa {
|
for i, _ := range sa {
|
||||||
sa[i] = i
|
sa[i] = i
|
||||||
}
|
}
|
||||||
x := &index{data, sa}
|
x := &Index{data, sa}
|
||||||
sort.Sort(x)
|
sort.Sort((*index)(x))
|
||||||
return (*Index)(x)
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ func (x *Index) search(s []byte) int {
|
|||||||
// Lookup returns an unsorted list of at most n indices where the byte string s
|
// 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.
|
// 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.
|
// The result is nil if s is empty, s is not found, or n == 0.
|
||||||
// Lookup time is O((log(N) + len(res))*len(s)) where N is the
|
// Lookup time is O((log(N) + len(result))*len(s)) where N is the
|
||||||
// size of the indexed data.
|
// size of the indexed data.
|
||||||
//
|
//
|
||||||
func (x *Index) Lookup(s []byte, n int) []int {
|
func (x *Index) Lookup(s []byte, n int) []int {
|
||||||
@ -102,14 +102,8 @@ func (x *Index) Lookup(s []byte, n int) []int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// index is like Index; it is only used to hide the sort.Interface methods
|
// index is used to hide the sort.Interface
|
||||||
type index struct {
|
type index Index
|
||||||
data []byte
|
|
||||||
sa []int
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// index implements sort.Interface
|
|
||||||
|
|
||||||
func (x *index) Len() int { return len(x.sa) }
|
func (x *index) Len() int { return len(x.sa) }
|
||||||
func (x *index) Less(i, j int) bool { return bytes.Compare(x.at(i), x.at(j)) < 0 }
|
func (x *index) Less(i, j int) bool { return bytes.Compare(x.at(i), x.at(j)) < 0 }
|
||||||
|
Loading…
Reference in New Issue
Block a user