aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/container/vector
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-07-14 14:39:40 -0700
committerRobert Griesemer <gri@golang.org>2011-07-14 14:39:40 -0700
commit90564a92565877d19e456694ac4e2ef205720432 (patch)
tree8cb7e9ba936b3721ed7e3120e95fa419859ea20f /src/pkg/container/vector
parent58e19aa4cb8656cdb757172647dfcb028029185e (diff)
downloadgo-90564a92565877d19e456694ac4e2ef205720432.tar.xz
go/printer: changed max. number of newlines from 3 to 2
manual changes in src/pkg/go/printer, src/cmd/gofix/signal_test.go (cd src/cmd/gofix/testdata; gofmt -w *.in *.out) (cd src/pkg/go/printer; gotest -update) gofmt -w misc src runs all tests R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4715041
Diffstat (limited to 'src/pkg/container/vector')
-rw-r--r--src/pkg/container/vector/defs.go8
-rw-r--r--src/pkg/container/vector/intvector.go20
-rw-r--r--src/pkg/container/vector/intvector_test.go13
-rw-r--r--src/pkg/container/vector/nogen_test.go9
-rw-r--r--src/pkg/container/vector/numbers_test.go8
-rw-r--r--src/pkg/container/vector/stringvector.go20
-rw-r--r--src/pkg/container/vector/stringvector_test.go13
-rw-r--r--src/pkg/container/vector/vector.go20
-rw-r--r--src/pkg/container/vector/vector_test.go13
9 files changed, 0 insertions, 124 deletions
diff --git a/src/pkg/container/vector/defs.go b/src/pkg/container/vector/defs.go
index bfb5481fb8..6d6b2ac81a 100644
--- a/src/pkg/container/vector/defs.go
+++ b/src/pkg/container/vector/defs.go
@@ -6,29 +6,24 @@
// Vectors grow and shrink dynamically as necessary.
package vector
-
// Vector is a container for numbered sequences of elements of type interface{}.
// A vector's length and capacity adjusts automatically as necessary.
// The zero value for Vector is an empty vector ready to use.
type Vector []interface{}
-
// IntVector is a container for numbered sequences of elements of type int.
// A vector's length and capacity adjusts automatically as necessary.
// The zero value for IntVector is an empty vector ready to use.
type IntVector []int
-
// StringVector is a container for numbered sequences of elements of type string.
// A vector's length and capacity adjusts automatically as necessary.
// The zero value for StringVector is an empty vector ready to use.
type StringVector []string
-
// Initial underlying array size
const initialSize = 8
-
// Partial sort.Interface support
// LessInterface provides partial support of the sort.Interface.
@@ -36,16 +31,13 @@ type LessInterface interface {
Less(y interface{}) bool
}
-
// Less returns a boolean denoting whether the i'th element is less than the j'th element.
func (p *Vector) Less(i, j int) bool { return (*p)[i].(LessInterface).Less((*p)[j]) }
-
// sort.Interface support
// Less returns a boolean denoting whether the i'th element is less than the j'th element.
func (p *IntVector) Less(i, j int) bool { return (*p)[i] < (*p)[j] }
-
// Less returns a boolean denoting whether the i'th element is less than the j'th element.
func (p *StringVector) Less(i, j int) bool { return (*p)[i] < (*p)[j] }
diff --git a/src/pkg/container/vector/intvector.go b/src/pkg/container/vector/intvector.go
index 5ad9e294b7..aa88cfeb36 100644
--- a/src/pkg/container/vector/intvector.go
+++ b/src/pkg/container/vector/intvector.go
@@ -7,7 +7,6 @@
package vector
-
func (p *IntVector) realloc(length, capacity int) (b []int) {
if capacity < initialSize {
capacity = initialSize
@@ -21,7 +20,6 @@ func (p *IntVector) realloc(length, capacity int) (b []int) {
return
}
-
// Insert n elements at position i.
func (p *IntVector) Expand(i, n int) {
a := *p
@@ -51,11 +49,9 @@ func (p *IntVector) Expand(i, n int) {
*p = a
}
-
// Insert n elements at the end of a vector.
func (p *IntVector) Extend(n int) { p.Expand(len(*p), n) }
-
// Resize changes the length and capacity of a vector.
// If the new length is shorter than the current length, Resize discards
// trailing elements. If the new length is longer than the current length,
@@ -80,30 +76,24 @@ func (p *IntVector) Resize(length, capacity int) *IntVector {
return p
}
-
// Len returns the number of elements in the vector.
// Same as len(*p).
func (p *IntVector) Len() int { return len(*p) }
-
// Cap returns the capacity of the vector; that is, the
// maximum length the vector can grow without resizing.
// Same as cap(*p).
func (p *IntVector) Cap() int { return cap(*p) }
-
// At returns the i'th element of the vector.
func (p *IntVector) At(i int) int { return (*p)[i] }
-
// Set sets the i'th element of the vector to value x.
func (p *IntVector) Set(i int, x int) { (*p)[i] = x }
-
// Last returns the element in the vector of highest index.
func (p *IntVector) Last() int { return (*p)[len(*p)-1] }
-
// Copy makes a copy of the vector and returns it.
func (p *IntVector) Copy() IntVector {
arr := make(IntVector, len(*p))
@@ -111,7 +101,6 @@ func (p *IntVector) Copy() IntVector {
return arr
}
-
// Insert inserts into the vector an element of value x before
// the current element at index i.
func (p *IntVector) Insert(i int, x int) {
@@ -119,7 +108,6 @@ func (p *IntVector) Insert(i int, x int) {
(*p)[i] = x
}
-
// Delete deletes the i'th element of the vector. The gap is closed so the old
// element at index i+1 has index i afterwards.
func (p *IntVector) Delete(i int) {
@@ -132,7 +120,6 @@ func (p *IntVector) Delete(i int) {
*p = a[0 : n-1]
}
-
// InsertVector inserts into the vector the contents of the vector
// x such that the 0th element of x appears at index i after insertion.
func (p *IntVector) InsertVector(i int, x *IntVector) {
@@ -142,7 +129,6 @@ func (p *IntVector) InsertVector(i int, x *IntVector) {
copy((*p)[i:i+len(b)], b)
}
-
// Cut deletes elements i through j-1, inclusive.
func (p *IntVector) Cut(i, j int) {
a := *p
@@ -158,7 +144,6 @@ func (p *IntVector) Cut(i, j int) {
*p = a[0:m]
}
-
// Slice returns a new sub-vector by slicing the old one to extract slice [i:j].
// The elements are copied. The original vector is unchanged.
func (p *IntVector) Slice(i, j int) *IntVector {
@@ -168,13 +153,11 @@ func (p *IntVector) Slice(i, j int) *IntVector {
return &s
}
-
// Convenience wrappers
// Push appends x to the end of the vector.
func (p *IntVector) Push(x int) { p.Insert(len(*p), x) }
-
// Pop deletes the last element of the vector.
func (p *IntVector) Pop() int {
a := *p
@@ -187,18 +170,15 @@ func (p *IntVector) Pop() int {
return x
}
-
// AppendVector appends the entire vector x to the end of this vector.
func (p *IntVector) AppendVector(x *IntVector) { p.InsertVector(len(*p), x) }
-
// Swap exchanges the elements at indexes i and j.
func (p *IntVector) Swap(i, j int) {
a := *p
a[i], a[j] = a[j], a[i]
}
-
// Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p.
func (p *IntVector) Do(f func(elem int)) {
diff --git a/src/pkg/container/vector/intvector_test.go b/src/pkg/container/vector/intvector_test.go
index 1e38a1982f..b825af9122 100644
--- a/src/pkg/container/vector/intvector_test.go
+++ b/src/pkg/container/vector/intvector_test.go
@@ -9,7 +9,6 @@ package vector
import "testing"
-
func TestIntZeroLen(t *testing.T) {
a := new(IntVector)
if a.Len() != 0 {
@@ -27,7 +26,6 @@ func TestIntZeroLen(t *testing.T) {
}
}
-
func TestIntResize(t *testing.T) {
var a IntVector
checkSize(t, &a, 0, 0)
@@ -40,7 +38,6 @@ func TestIntResize(t *testing.T) {
checkSize(t, a.Resize(11, 100), 11, 100)
}
-
func TestIntResize2(t *testing.T) {
var a IntVector
checkSize(t, &a, 0, 0)
@@ -62,7 +59,6 @@ func TestIntResize2(t *testing.T) {
}
}
-
func checkIntZero(t *testing.T, a *IntVector, i int) {
for j := 0; j < i; j++ {
if a.At(j) == intzero {
@@ -82,7 +78,6 @@ func checkIntZero(t *testing.T, a *IntVector, i int) {
}
}
-
func TestIntTrailingElements(t *testing.T) {
var a IntVector
for i := 0; i < 10; i++ {
@@ -95,7 +90,6 @@ func TestIntTrailingElements(t *testing.T) {
checkIntZero(t, &a, 5)
}
-
func TestIntAccess(t *testing.T) {
const n = 100
var a IntVector
@@ -120,7 +114,6 @@ func TestIntAccess(t *testing.T) {
}
}
-
func TestIntInsertDeleteClear(t *testing.T) {
const n = 100
var a IntVector
@@ -207,7 +200,6 @@ func TestIntInsertDeleteClear(t *testing.T) {
}
}
-
func verify_sliceInt(t *testing.T, x *IntVector, elt, i, j int) {
for k := i; k < j; k++ {
if elem2IntValue(x.At(k)) != int2IntValue(elt) {
@@ -223,7 +215,6 @@ func verify_sliceInt(t *testing.T, x *IntVector, elt, i, j int) {
}
}
-
func verify_patternInt(t *testing.T, x *IntVector, a, b, c int) {
n := a + b + c
if x.Len() != n {
@@ -237,7 +228,6 @@ func verify_patternInt(t *testing.T, x *IntVector, a, b, c int) {
verify_sliceInt(t, x, 0, a+b, n)
}
-
func make_vectorInt(elt, len int) *IntVector {
x := new(IntVector).Resize(len, 0)
for i := 0; i < len; i++ {
@@ -246,7 +236,6 @@ func make_vectorInt(elt, len int) *IntVector {
return x
}
-
func TestIntInsertVector(t *testing.T) {
// 1
a := make_vectorInt(0, 0)
@@ -270,7 +259,6 @@ func TestIntInsertVector(t *testing.T) {
verify_patternInt(t, a, 8, 1000, 2)
}
-
func TestIntDo(t *testing.T) {
const n = 25
const salt = 17
@@ -325,7 +313,6 @@ func TestIntDo(t *testing.T) {
}
-
func TestIntVectorCopy(t *testing.T) {
// verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10
diff --git a/src/pkg/container/vector/nogen_test.go b/src/pkg/container/vector/nogen_test.go
index 790d3749fc..7b6a25952b 100644
--- a/src/pkg/container/vector/nogen_test.go
+++ b/src/pkg/container/vector/nogen_test.go
@@ -4,7 +4,6 @@
package vector
-
import (
"fmt"
"sort"
@@ -17,28 +16,23 @@ var (
strzero string
)
-
func int2Value(x int) int { return x }
func int2IntValue(x int) int { return x }
func int2StrValue(x int) string { return string(x) }
-
func elem2Value(x interface{}) int { return x.(int) }
func elem2IntValue(x int) int { return x }
func elem2StrValue(x string) string { return x }
-
func intf2Value(x interface{}) int { return x.(int) }
func intf2IntValue(x interface{}) int { return x.(int) }
func intf2StrValue(x interface{}) string { return x.(string) }
-
type VectorInterface interface {
Len() int
Cap() int
}
-
func checkSize(t *testing.T, v VectorInterface, len, cap int) {
if v.Len() != len {
t.Errorf("%T expected len = %d; found %d", v, len, v.Len())
@@ -48,10 +42,8 @@ func checkSize(t *testing.T, v VectorInterface, len, cap int) {
}
}
-
func val(i int) int { return i*991 - 1234 }
-
func TestSorting(t *testing.T) {
const n = 100
@@ -72,5 +64,4 @@ func TestSorting(t *testing.T) {
}
}
-
func tname(x interface{}) string { return fmt.Sprintf("%T: ", x) }
diff --git a/src/pkg/container/vector/numbers_test.go b/src/pkg/container/vector/numbers_test.go
index b83b0bfeef..abe01a8fb1 100644
--- a/src/pkg/container/vector/numbers_test.go
+++ b/src/pkg/container/vector/numbers_test.go
@@ -11,10 +11,8 @@ import (
"testing"
)
-
const memTestN = 1000000
-
func s(n uint64) string {
str := fmt.Sprintf("%d", n)
lens := len(str)
@@ -31,7 +29,6 @@ func s(n uint64) string {
return strings.Join(a, " ")
}
-
func TestVectorNums(t *testing.T) {
if testing.Short() {
return
@@ -52,7 +49,6 @@ func TestVectorNums(t *testing.T) {
t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float64(n)/memTestN)
}
-
func TestIntVectorNums(t *testing.T) {
if testing.Short() {
return
@@ -73,7 +69,6 @@ func TestIntVectorNums(t *testing.T) {
t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float64(n)/memTestN)
}
-
func TestStringVectorNums(t *testing.T) {
if testing.Short() {
return
@@ -94,7 +89,6 @@ func TestStringVectorNums(t *testing.T) {
t.Logf("%T.Push(%#v), n = %s: Alloc/n = %.2f\n", v, c, s(memTestN), float64(n)/memTestN)
}
-
func BenchmarkVectorNums(b *testing.B) {
c := int(0)
var v Vector
@@ -106,7 +100,6 @@ func BenchmarkVectorNums(b *testing.B) {
}
}
-
func BenchmarkIntVectorNums(b *testing.B) {
c := int(0)
var v IntVector
@@ -118,7 +111,6 @@ func BenchmarkIntVectorNums(b *testing.B) {
}
}
-
func BenchmarkStringVectorNums(b *testing.B) {
c := ""
var v StringVector
diff --git a/src/pkg/container/vector/stringvector.go b/src/pkg/container/vector/stringvector.go
index 852685f5a1..dc81f06b74 100644
--- a/src/pkg/container/vector/stringvector.go
+++ b/src/pkg/container/vector/stringvector.go
@@ -7,7 +7,6 @@
package vector
-
func (p *StringVector) realloc(length, capacity int) (b []string) {
if capacity < initialSize {
capacity = initialSize
@@ -21,7 +20,6 @@ func (p *StringVector) realloc(length, capacity int) (b []string) {
return
}
-
// Insert n elements at position i.
func (p *StringVector) Expand(i, n int) {
a := *p
@@ -51,11 +49,9 @@ func (p *StringVector) Expand(i, n int) {
*p = a
}
-
// Insert n elements at the end of a vector.
func (p *StringVector) Extend(n int) { p.Expand(len(*p), n) }
-
// Resize changes the length and capacity of a vector.
// If the new length is shorter than the current length, Resize discards
// trailing elements. If the new length is longer than the current length,
@@ -80,30 +76,24 @@ func (p *StringVector) Resize(length, capacity int) *StringVector {
return p
}
-
// Len returns the number of elements in the vector.
// Same as len(*p).
func (p *StringVector) Len() int { return len(*p) }
-
// Cap returns the capacity of the vector; that is, the
// maximum length the vector can grow without resizing.
// Same as cap(*p).
func (p *StringVector) Cap() int { return cap(*p) }
-
// At returns the i'th element of the vector.
func (p *StringVector) At(i int) string { return (*p)[i] }
-
// Set sets the i'th element of the vector to value x.
func (p *StringVector) Set(i int, x string) { (*p)[i] = x }
-
// Last returns the element in the vector of highest index.
func (p *StringVector) Last() string { return (*p)[len(*p)-1] }
-
// Copy makes a copy of the vector and returns it.
func (p *StringVector) Copy() StringVector {
arr := make(StringVector, len(*p))
@@ -111,7 +101,6 @@ func (p *StringVector) Copy() StringVector {
return arr
}
-
// Insert inserts into the vector an element of value x before
// the current element at index i.
func (p *StringVector) Insert(i int, x string) {
@@ -119,7 +108,6 @@ func (p *StringVector) Insert(i int, x string) {
(*p)[i] = x
}
-
// Delete deletes the i'th element of the vector. The gap is closed so the old
// element at index i+1 has index i afterwards.
func (p *StringVector) Delete(i int) {
@@ -132,7 +120,6 @@ func (p *StringVector) Delete(i int) {
*p = a[0 : n-1]
}
-
// InsertVector inserts into the vector the contents of the vector
// x such that the 0th element of x appears at index i after insertion.
func (p *StringVector) InsertVector(i int, x *StringVector) {
@@ -142,7 +129,6 @@ func (p *StringVector) InsertVector(i int, x *StringVector) {
copy((*p)[i:i+len(b)], b)
}
-
// Cut deletes elements i through j-1, inclusive.
func (p *StringVector) Cut(i, j int) {
a := *p
@@ -158,7 +144,6 @@ func (p *StringVector) Cut(i, j int) {
*p = a[0:m]
}
-
// Slice returns a new sub-vector by slicing the old one to extract slice [i:j].
// The elements are copied. The original vector is unchanged.
func (p *StringVector) Slice(i, j int) *StringVector {
@@ -168,13 +153,11 @@ func (p *StringVector) Slice(i, j int) *StringVector {
return &s
}
-
// Convenience wrappers
// Push appends x to the end of the vector.
func (p *StringVector) Push(x string) { p.Insert(len(*p), x) }
-
// Pop deletes the last element of the vector.
func (p *StringVector) Pop() string {
a := *p
@@ -187,18 +170,15 @@ func (p *StringVector) Pop() string {
return x
}
-
// AppendVector appends the entire vector x to the end of this vector.
func (p *StringVector) AppendVector(x *StringVector) { p.InsertVector(len(*p), x) }
-
// Swap exchanges the elements at indexes i and j.
func (p *StringVector) Swap(i, j int) {
a := *p
a[i], a[j] = a[j], a[i]
}
-
// Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p.
func (p *StringVector) Do(f func(elem string)) {
diff --git a/src/pkg/container/vector/stringvector_test.go b/src/pkg/container/vector/stringvector_test.go
index 776ae26dea..c75676f786 100644
--- a/src/pkg/container/vector/stringvector_test.go
+++ b/src/pkg/container/vector/stringvector_test.go
@@ -9,7 +9,6 @@ package vector
import "testing"
-
func TestStrZeroLen(t *testing.T) {
a := new(StringVector)
if a.Len() != 0 {
@@ -27,7 +26,6 @@ func TestStrZeroLen(t *testing.T) {
}
}
-
func TestStrResize(t *testing.T) {
var a StringVector
checkSize(t, &a, 0, 0)
@@ -40,7 +38,6 @@ func TestStrResize(t *testing.T) {
checkSize(t, a.Resize(11, 100), 11, 100)
}
-
func TestStrResize2(t *testing.T) {
var a StringVector
checkSize(t, &a, 0, 0)
@@ -62,7 +59,6 @@ func TestStrResize2(t *testing.T) {
}
}
-
func checkStrZero(t *testing.T, a *StringVector, i int) {
for j := 0; j < i; j++ {
if a.At(j) == strzero {
@@ -82,7 +78,6 @@ func checkStrZero(t *testing.T, a *StringVector, i int) {
}
}
-
func TestStrTrailingElements(t *testing.T) {
var a StringVector
for i := 0; i < 10; i++ {
@@ -95,7 +90,6 @@ func TestStrTrailingElements(t *testing.T) {
checkStrZero(t, &a, 5)
}
-
func TestStrAccess(t *testing.T) {
const n = 100
var a StringVector
@@ -120,7 +114,6 @@ func TestStrAccess(t *testing.T) {
}
}
-
func TestStrInsertDeleteClear(t *testing.T) {
const n = 100
var a StringVector
@@ -207,7 +200,6 @@ func TestStrInsertDeleteClear(t *testing.T) {
}
}
-
func verify_sliceStr(t *testing.T, x *StringVector, elt, i, j int) {
for k := i; k < j; k++ {
if elem2StrValue(x.At(k)) != int2StrValue(elt) {
@@ -223,7 +215,6 @@ func verify_sliceStr(t *testing.T, x *StringVector, elt, i, j int) {
}
}
-
func verify_patternStr(t *testing.T, x *StringVector, a, b, c int) {
n := a + b + c
if x.Len() != n {
@@ -237,7 +228,6 @@ func verify_patternStr(t *testing.T, x *StringVector, a, b, c int) {
verify_sliceStr(t, x, 0, a+b, n)
}
-
func make_vectorStr(elt, len int) *StringVector {
x := new(StringVector).Resize(len, 0)
for i := 0; i < len; i++ {
@@ -246,7 +236,6 @@ func make_vectorStr(elt, len int) *StringVector {
return x
}
-
func TestStrInsertVector(t *testing.T) {
// 1
a := make_vectorStr(0, 0)
@@ -270,7 +259,6 @@ func TestStrInsertVector(t *testing.T) {
verify_patternStr(t, a, 8, 1000, 2)
}
-
func TestStrDo(t *testing.T) {
const n = 25
const salt = 17
@@ -325,7 +313,6 @@ func TestStrDo(t *testing.T) {
}
-
func TestStrVectorCopy(t *testing.T) {
// verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10
diff --git a/src/pkg/container/vector/vector.go b/src/pkg/container/vector/vector.go
index f43e4d23ca..8470ec067a 100644
--- a/src/pkg/container/vector/vector.go
+++ b/src/pkg/container/vector/vector.go
@@ -7,7 +7,6 @@
package vector
-
func (p *Vector) realloc(length, capacity int) (b []interface{}) {
if capacity < initialSize {
capacity = initialSize
@@ -21,7 +20,6 @@ func (p *Vector) realloc(length, capacity int) (b []interface{}) {
return
}
-
// Insert n elements at position i.
func (p *Vector) Expand(i, n int) {
a := *p
@@ -51,11 +49,9 @@ func (p *Vector) Expand(i, n int) {
*p = a
}
-
// Insert n elements at the end of a vector.
func (p *Vector) Extend(n int) { p.Expand(len(*p), n) }
-
// Resize changes the length and capacity of a vector.
// If the new length is shorter than the current length, Resize discards
// trailing elements. If the new length is longer than the current length,
@@ -80,30 +76,24 @@ func (p *Vector) Resize(length, capacity int) *Vector {
return p
}
-
// Len returns the number of elements in the vector.
// Same as len(*p).
func (p *Vector) Len() int { return len(*p) }
-
// Cap returns the capacity of the vector; that is, the
// maximum length the vector can grow without resizing.
// Same as cap(*p).
func (p *Vector) Cap() int { return cap(*p) }
-
// At returns the i'th element of the vector.
func (p *Vector) At(i int) interface{} { return (*p)[i] }
-
// Set sets the i'th element of the vector to value x.
func (p *Vector) Set(i int, x interface{}) { (*p)[i] = x }
-
// Last returns the element in the vector of highest index.
func (p *Vector) Last() interface{} { return (*p)[len(*p)-1] }
-
// Copy makes a copy of the vector and returns it.
func (p *Vector) Copy() Vector {
arr := make(Vector, len(*p))
@@ -111,7 +101,6 @@ func (p *Vector) Copy() Vector {
return arr
}
-
// Insert inserts into the vector an element of value x before
// the current element at index i.
func (p *Vector) Insert(i int, x interface{}) {
@@ -119,7 +108,6 @@ func (p *Vector) Insert(i int, x interface{}) {
(*p)[i] = x
}
-
// Delete deletes the i'th element of the vector. The gap is closed so the old
// element at index i+1 has index i afterwards.
func (p *Vector) Delete(i int) {
@@ -132,7 +120,6 @@ func (p *Vector) Delete(i int) {
*p = a[0 : n-1]
}
-
// InsertVector inserts into the vector the contents of the vector
// x such that the 0th element of x appears at index i after insertion.
func (p *Vector) InsertVector(i int, x *Vector) {
@@ -142,7 +129,6 @@ func (p *Vector) InsertVector(i int, x *Vector) {
copy((*p)[i:i+len(b)], b)
}
-
// Cut deletes elements i through j-1, inclusive.
func (p *Vector) Cut(i, j int) {
a := *p
@@ -158,7 +144,6 @@ func (p *Vector) Cut(i, j int) {
*p = a[0:m]
}
-
// Slice returns a new sub-vector by slicing the old one to extract slice [i:j].
// The elements are copied. The original vector is unchanged.
func (p *Vector) Slice(i, j int) *Vector {
@@ -168,13 +153,11 @@ func (p *Vector) Slice(i, j int) *Vector {
return &s
}
-
// Convenience wrappers
// Push appends x to the end of the vector.
func (p *Vector) Push(x interface{}) { p.Insert(len(*p), x) }
-
// Pop deletes the last element of the vector.
func (p *Vector) Pop() interface{} {
a := *p
@@ -187,18 +170,15 @@ func (p *Vector) Pop() interface{} {
return x
}
-
// AppendVector appends the entire vector x to the end of this vector.
func (p *Vector) AppendVector(x *Vector) { p.InsertVector(len(*p), x) }
-
// Swap exchanges the elements at indexes i and j.
func (p *Vector) Swap(i, j int) {
a := *p
a[i], a[j] = a[j], a[i]
}
-
// Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p.
func (p *Vector) Do(f func(elem interface{})) {
diff --git a/src/pkg/container/vector/vector_test.go b/src/pkg/container/vector/vector_test.go
index a9c4ceb55a..a7f47b8c2a 100644
--- a/src/pkg/container/vector/vector_test.go
+++ b/src/pkg/container/vector/vector_test.go
@@ -9,7 +9,6 @@ package vector
import "testing"
-
func TestZeroLen(t *testing.T) {
a := new(Vector)
if a.Len() != 0 {
@@ -27,7 +26,6 @@ func TestZeroLen(t *testing.T) {
}
}
-
func TestResize(t *testing.T) {
var a Vector
checkSize(t, &a, 0, 0)
@@ -40,7 +38,6 @@ func TestResize(t *testing.T) {
checkSize(t, a.Resize(11, 100), 11, 100)
}
-
func TestResize2(t *testing.T) {
var a Vector
checkSize(t, &a, 0, 0)
@@ -62,7 +59,6 @@ func TestResize2(t *testing.T) {
}
}
-
func checkZero(t *testing.T, a *Vector, i int) {
for j := 0; j < i; j++ {
if a.At(j) == zero {
@@ -82,7 +78,6 @@ func checkZero(t *testing.T, a *Vector, i int) {
}
}
-
func TestTrailingElements(t *testing.T) {
var a Vector
for i := 0; i < 10; i++ {
@@ -95,7 +90,6 @@ func TestTrailingElements(t *testing.T) {
checkZero(t, &a, 5)
}
-
func TestAccess(t *testing.T) {
const n = 100
var a Vector
@@ -120,7 +114,6 @@ func TestAccess(t *testing.T) {
}
}
-
func TestInsertDeleteClear(t *testing.T) {
const n = 100
var a Vector
@@ -207,7 +200,6 @@ func TestInsertDeleteClear(t *testing.T) {
}
}
-
func verify_slice(t *testing.T, x *Vector, elt, i, j int) {
for k := i; k < j; k++ {
if elem2Value(x.At(k)) != int2Value(elt) {
@@ -223,7 +215,6 @@ func verify_slice(t *testing.T, x *Vector, elt, i, j int) {
}
}
-
func verify_pattern(t *testing.T, x *Vector, a, b, c int) {
n := a + b + c
if x.Len() != n {
@@ -237,7 +228,6 @@ func verify_pattern(t *testing.T, x *Vector, a, b, c int) {
verify_slice(t, x, 0, a+b, n)
}
-
func make_vector(elt, len int) *Vector {
x := new(Vector).Resize(len, 0)
for i := 0; i < len; i++ {
@@ -246,7 +236,6 @@ func make_vector(elt, len int) *Vector {
return x
}
-
func TestInsertVector(t *testing.T) {
// 1
a := make_vector(0, 0)
@@ -270,7 +259,6 @@ func TestInsertVector(t *testing.T) {
verify_pattern(t, a, 8, 1000, 2)
}
-
func TestDo(t *testing.T) {
const n = 25
const salt = 17
@@ -325,7 +313,6 @@ func TestDo(t *testing.T) {
}
-
func TestVectorCopy(t *testing.T) {
// verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10