summaryrefslogtreecommitdiff
path: root/libgo/go/index
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-09-16 15:47:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-09-16 15:47:21 +0000
commitadb0401dac41c81571722312d4586b2693f95aa6 (patch)
treeea2b52e3c258d6b6d9356977c683c7f72a4a5fd5 /libgo/go/index
parent5548ca3540bccbc908a45942896d635ea5f1c23f (diff)
downloadgcc-adb0401dac41c81571722312d4586b2693f95aa6.tar.gz
Update Go library to r60.
From-SVN: r178910
Diffstat (limited to 'libgo/go/index')
-rw-r--r--libgo/go/index/suffixarray/qsufsort.go4
-rw-r--r--libgo/go/index/suffixarray/suffixarray.go11
-rw-r--r--libgo/go/index/suffixarray/suffixarray_test.go18
3 files changed, 6 insertions, 27 deletions
diff --git a/libgo/go/index/suffixarray/qsufsort.go b/libgo/go/index/suffixarray/qsufsort.go
index 9751b5c7663..30c1104428c 100644
--- a/libgo/go/index/suffixarray/qsufsort.go
+++ b/libgo/go/index/suffixarray/qsufsort.go
@@ -72,7 +72,6 @@ func qsufsort(data []byte) []int {
return sa
}
-
func sortedByFirstByte(data []byte) []int {
// total byte counts
var count [256]int
@@ -93,7 +92,6 @@ func sortedByFirstByte(data []byte) []int {
return sa
}
-
func initGroups(sa []int, data []byte) []int {
// label contiguous same-letter groups with the same group number
inv := make([]int, len(data))
@@ -133,7 +131,6 @@ func initGroups(sa []int, data []byte) []int {
return inv
}
-
type suffixSortable struct {
sa []int
inv []int
@@ -144,7 +141,6 @@ func (x *suffixSortable) Len() int { return len(x.sa) }
func (x *suffixSortable) Less(i, j int) bool { return x.inv[x.sa[i]+x.h] < x.inv[x.sa[j]+x.h] }
func (x *suffixSortable) Swap(i, j int) { x.sa[i], x.sa[j] = x.sa[j], x.sa[i] }
-
func (x *suffixSortable) updateGroups(offset int) {
bounds := make([]int, 0, 4)
group := x.inv[x.sa[0]+x.h]
diff --git a/libgo/go/index/suffixarray/suffixarray.go b/libgo/go/index/suffixarray/suffixarray.go
index 079b7d8ed0b..82e98d2ef54 100644
--- a/libgo/go/index/suffixarray/suffixarray.go
+++ b/libgo/go/index/suffixarray/suffixarray.go
@@ -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 {
diff --git a/libgo/go/index/suffixarray/suffixarray_test.go b/libgo/go/index/suffixarray/suffixarray_test.go
index e85267f17f5..02374850056 100644
--- a/libgo/go/index/suffixarray/suffixarray_test.go
+++ b/libgo/go/index/suffixarray/suffixarray_test.go
@@ -6,21 +6,18 @@ package suffixarray
import (
"bytes"
- "container/vector"
"regexp"
"sort"
"strings"
"testing"
)
-
type testCase struct {
name string // name of test case
source string // source to index
patterns []string // patterns to lookup
}
-
var testCases = []testCase{
{
"empty string",
@@ -107,10 +104,9 @@ var testCases = []testCase{
},
}
-
-// find all occurrences of s in source; report at most n occurences
+// find all occurrences of s in source; report at most n occurrences
func find(src, s string, n int) []int {
- var res vector.IntVector
+ var res []int
if s != "" && n != 0 {
// find at most n occurrences of s in src
for i := -1; n < 0 || len(res) < n; {
@@ -119,13 +115,12 @@ func find(src, s string, n int) []int {
break
}
i += j + 1
- res.Push(i)
+ res = append(res, i)
}
}
return res
}
-
func testLookup(t *testing.T, tc *testCase, x *Index, s string, n int) {
res := x.Lookup([]byte(s), n)
exp := find(tc.source, s, n)
@@ -141,7 +136,7 @@ func testLookup(t *testing.T, tc *testCase, x *Index, s string, n int) {
// we cannot simply check that the res and exp lists are equal
// check that each result is in fact a correct match and there are no duplicates
- sort.SortInts(res)
+ sort.Ints(res)
for i, r := range res {
if r < 0 || len(tc.source) <= r {
t.Errorf("test %q, lookup %q, result %d (n = %d): index %d out of range [0, %d[", tc.name, s, i, n, r, len(tc.source))
@@ -164,7 +159,6 @@ func testLookup(t *testing.T, tc *testCase, x *Index, s string, n int) {
}
}
-
func testFindAllIndex(t *testing.T, tc *testCase, x *Index, rx *regexp.Regexp, n int) {
res := x.FindAllIndex(rx, n)
exp := rx.FindAllStringIndex(tc.source, n)
@@ -200,7 +194,6 @@ func testFindAllIndex(t *testing.T, tc *testCase, x *Index, rx *regexp.Regexp, n
}
}
-
func testLookups(t *testing.T, tc *testCase, x *Index, n int) {
for _, pat := range tc.patterns {
testLookup(t, tc, x, pat, n)
@@ -210,7 +203,6 @@ func testLookups(t *testing.T, tc *testCase, x *Index, n int) {
}
}
-
// index is used to hide the sort.Interface
type index Index
@@ -219,14 +211,12 @@ func (x *index) Less(i, j int) bool { return bytes.Compare(x.at(i), x.at(j)) < 0
func (x *index) Swap(i, j int) { x.sa[i], x.sa[j] = x.sa[j], x.sa[i] }
func (a *index) at(i int) []byte { return a.data[a.sa[i]:] }
-
func testConstruction(t *testing.T, tc *testCase, x *Index) {
if !sort.IsSorted((*index)(x)) {
t.Errorf("testConstruction failed %s", tc.name)
}
}
-
func TestIndex(t *testing.T) {
for _, tc := range testCases {
x := New([]byte(tc.source))