]> Cypherpunks repositories - gostls13.git/commitdiff
container/vector: rename Data() -> Copy()
authorRobert Griesemer <gri@golang.org>
Tue, 13 Jul 2010 00:22:21 +0000 (17:22 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 13 Jul 2010 00:22:21 +0000 (17:22 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/1814043

src/pkg/container/vector/Makefile
src/pkg/container/vector/intvector.go
src/pkg/container/vector/intvector_test.go
src/pkg/container/vector/stringvector.go
src/pkg/container/vector/stringvector_test.go
src/pkg/container/vector/vector.go
src/pkg/container/vector/vector_test.go
src/pkg/exp/iterable/iterable.go
src/pkg/exp/iterable/iterable_test.go

index f664b43f947696fd386da6341825bf707d8e2a6e..1eb310c6d890e3469c6ecb3a61806b4e786d3071 100644 (file)
@@ -42,7 +42,7 @@ generate: vector.go vector_test.go
        | gofmt -r='make_vector -> make_vectorInt'\
        | gofmt -r='TestInsertVector -> TestIntInsertVector'\
        | gofmt -r='TestDo -> TestIntDo'\
-       | gofmt -r='TestVectorData -> TestIntVectorData'\
+       | gofmt -r='TestVectorCopy -> TestIntVectorCopy'\
        | gofmt -r='interface{} -> int'\
        > intvector_test.go\
        
@@ -64,6 +64,6 @@ generate: vector.go vector_test.go
        | gofmt -r='make_vector -> make_vectorStr'\
        | gofmt -r='TestInsertVector -> TestStrInsertVector'\
        | gofmt -r='TestDo -> TestStrDo'\
-       | gofmt -r='TestVectorData -> TestStrVectorData'\
+       | gofmt -r='TestVectorCopy -> TestStrVectorCopy'\
        | gofmt -r='interface{} -> string'\
        > stringvector_test.go
index 5f4d6fa3d73eab9299f7e7e5616a6e078f6361e5..5ad9e294b75435357eb38fd1c6a2e612f327f6e4 100644 (file)
@@ -104,8 +104,8 @@ func (p *IntVector) Set(i int, x int) { (*p)[i] = x }
 func (p *IntVector) Last() int { return (*p)[len(*p)-1] }
 
 
-// Data returns all the elements as a slice.
-func (p *IntVector) Data() []int {
+// Copy makes a copy of the vector and returns it.
+func (p *IntVector) Copy() IntVector {
        arr := make(IntVector, len(*p))
        copy(arr, *p)
        return arr
index 2f853ebfacdead3b364bed93958f0560390f4c7c..fcc7403b36d1bd73b3313ac1025f1d0a2a3bfcce 100644 (file)
@@ -326,14 +326,14 @@ func TestIntDo(t *testing.T) {
 }
 
 
-func TestIntVectorData(t *testing.T) {
-       // verify Data() returns a slice of a copy, not a slice of the original vector
+func TestIntVectorCopy(t *testing.T) {
+       // verify Copy() returns a copy, not simply a slice of the original vector
        const Len = 10
        var src IntVector
        for i := 0; i < Len; i++ {
                src.Push(int2IntValue(i * i))
        }
-       dest := src.Data()
+       dest := src.Copy()
        for i := 0; i < Len; i++ {
                src[i] = int2IntValue(-1)
                v := elem2IntValue(dest[i])
index a9b727a9083b857918674cbea086ee332b6fa15c..852685f5a129e55e9ef4c2d0025d53db09e8d2d8 100644 (file)
@@ -104,8 +104,8 @@ func (p *StringVector) Set(i int, x string) { (*p)[i] = x }
 func (p *StringVector) Last() string { return (*p)[len(*p)-1] }
 
 
-// Data returns all the elements as a slice.
-func (p *StringVector) Data() []string {
+// Copy makes a copy of the vector and returns it.
+func (p *StringVector) Copy() StringVector {
        arr := make(StringVector, len(*p))
        copy(arr, *p)
        return arr
index 1c05145a24a61a7206ddaa65a8173001e5c3ea18..2f3f082bdc481ad0ed23afd25754561b344e47da 100644 (file)
@@ -326,14 +326,14 @@ func TestStrDo(t *testing.T) {
 }
 
 
-func TestStrVectorData(t *testing.T) {
-       // verify Data() returns a slice of a copy, not a slice of the original vector
+func TestStrVectorCopy(t *testing.T) {
+       // verify Copy() returns a copy, not simply a slice of the original vector
        const Len = 10
        var src StringVector
        for i := 0; i < Len; i++ {
                src.Push(int2StrValue(i * i))
        }
-       dest := src.Data()
+       dest := src.Copy()
        for i := 0; i < Len; i++ {
                src[i] = int2StrValue(-1)
                v := elem2StrValue(dest[i])
index f219cdcaafdbf4d96366cc08799baf4f6f136385..f43e4d23ca2f701e1ffcb332cc4bb3d15c47c924 100644 (file)
@@ -104,8 +104,8 @@ func (p *Vector) Set(i int, x interface{}) { (*p)[i] = x }
 func (p *Vector) Last() interface{} { return (*p)[len(*p)-1] }
 
 
-// Data returns all the elements as a slice.
-func (p *Vector) Data() []interface{} {
+// Copy makes a copy of the vector and returns it.
+func (p *Vector) Copy() Vector {
        arr := make(Vector, len(*p))
        copy(arr, *p)
        return arr
index ba15398c28c6a137681b6e0f507172d0dda2429b..986dff2da7779257e49235803f68582dd97bb225 100644 (file)
@@ -326,14 +326,14 @@ func TestDo(t *testing.T) {
 }
 
 
-func TestVectorData(t *testing.T) {
-       // verify Data() returns a slice of a copy, not a slice of the original vector
+func TestVectorCopy(t *testing.T) {
+       // verify Copy() returns a copy, not simply a slice of the original vector
        const Len = 10
        var src Vector
        for i := 0; i < Len; i++ {
                src.Push(int2Value(i * i))
        }
-       dest := src.Data()
+       dest := src.Copy()
        for i := 0; i < Len; i++ {
                src[i] = int2Value(-1)
                v := elem2Value(dest[i])
index aefff94272ac1581d7192b2d857860fb98efe63a..85e5f38b0ebe179a39a697b609f390d24d9da9ae 100644 (file)
@@ -39,11 +39,11 @@ func Any(iter Iterable, f func(interface{}) bool) bool {
 
 // Data returns a slice containing the elements of iter.
 func Data(iter Iterable) []interface{} {
-       vec := new(vector.Vector)
+       var v vector.Vector
        for e := range iter.Iter() {
-               vec.Push(e)
+               v.Push(e)
        }
-       return vec.Data()
+       return v
 }
 
 // filteredIterable is a struct that implements Iterable with each element
index 1d60d4b910b0022112736efa37230cf6daf03307..26a2eecc4554a33ead9ba8247140e4b619adb97b 100644 (file)
@@ -371,7 +371,7 @@ func TestGroupBy(t *testing.T) {
        for x := range GroupBy(elevenToTwenty, intkey{}).Iter() {
                out.Push(x.(Group).Key)
        }
-       assertArraysAreEqual(t, out.Data(), elevenToTwenty)
+       assertArraysAreEqual(t, out, elevenToTwenty)
 }
 
 func TestUnique(t *testing.T) {