Commit d9c47cd8 authored by Robert Griesemer's avatar Robert Griesemer

container/vector: rename Data() -> Copy()

R=rsc
CC=golang-dev
https://golang.org/cl/1814043
parent 1930cd5d
...@@ -42,7 +42,7 @@ generate: vector.go vector_test.go ...@@ -42,7 +42,7 @@ generate: vector.go vector_test.go
| gofmt -r='make_vector -> make_vectorInt'\ | gofmt -r='make_vector -> make_vectorInt'\
| gofmt -r='TestInsertVector -> TestIntInsertVector'\ | gofmt -r='TestInsertVector -> TestIntInsertVector'\
| gofmt -r='TestDo -> TestIntDo'\ | gofmt -r='TestDo -> TestIntDo'\
| gofmt -r='TestVectorData -> TestIntVectorData'\ | gofmt -r='TestVectorCopy -> TestIntVectorCopy'\
| gofmt -r='interface{} -> int'\ | gofmt -r='interface{} -> int'\
> intvector_test.go\ > intvector_test.go\
...@@ -64,6 +64,6 @@ generate: vector.go vector_test.go ...@@ -64,6 +64,6 @@ generate: vector.go vector_test.go
| gofmt -r='make_vector -> make_vectorStr'\ | gofmt -r='make_vector -> make_vectorStr'\
| gofmt -r='TestInsertVector -> TestStrInsertVector'\ | gofmt -r='TestInsertVector -> TestStrInsertVector'\
| gofmt -r='TestDo -> TestStrDo'\ | gofmt -r='TestDo -> TestStrDo'\
| gofmt -r='TestVectorData -> TestStrVectorData'\ | gofmt -r='TestVectorCopy -> TestStrVectorCopy'\
| gofmt -r='interface{} -> string'\ | gofmt -r='interface{} -> string'\
> stringvector_test.go > stringvector_test.go
...@@ -104,8 +104,8 @@ func (p *IntVector) Set(i int, x int) { (*p)[i] = x } ...@@ -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] } func (p *IntVector) Last() int { return (*p)[len(*p)-1] }
// Data returns all the elements as a slice. // Copy makes a copy of the vector and returns it.
func (p *IntVector) Data() []int { func (p *IntVector) Copy() IntVector {
arr := make(IntVector, len(*p)) arr := make(IntVector, len(*p))
copy(arr, *p) copy(arr, *p)
return arr return arr
......
...@@ -326,14 +326,14 @@ func TestIntDo(t *testing.T) { ...@@ -326,14 +326,14 @@ func TestIntDo(t *testing.T) {
} }
func TestIntVectorData(t *testing.T) { func TestIntVectorCopy(t *testing.T) {
// verify Data() returns a slice of a copy, not a slice of the original vector // verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10 const Len = 10
var src IntVector var src IntVector
for i := 0; i < Len; i++ { for i := 0; i < Len; i++ {
src.Push(int2IntValue(i * i)) src.Push(int2IntValue(i * i))
} }
dest := src.Data() dest := src.Copy()
for i := 0; i < Len; i++ { for i := 0; i < Len; i++ {
src[i] = int2IntValue(-1) src[i] = int2IntValue(-1)
v := elem2IntValue(dest[i]) v := elem2IntValue(dest[i])
......
...@@ -104,8 +104,8 @@ func (p *StringVector) Set(i int, x string) { (*p)[i] = x } ...@@ -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] } func (p *StringVector) Last() string { return (*p)[len(*p)-1] }
// Data returns all the elements as a slice. // Copy makes a copy of the vector and returns it.
func (p *StringVector) Data() []string { func (p *StringVector) Copy() StringVector {
arr := make(StringVector, len(*p)) arr := make(StringVector, len(*p))
copy(arr, *p) copy(arr, *p)
return arr return arr
......
...@@ -326,14 +326,14 @@ func TestStrDo(t *testing.T) { ...@@ -326,14 +326,14 @@ func TestStrDo(t *testing.T) {
} }
func TestStrVectorData(t *testing.T) { func TestStrVectorCopy(t *testing.T) {
// verify Data() returns a slice of a copy, not a slice of the original vector // verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10 const Len = 10
var src StringVector var src StringVector
for i := 0; i < Len; i++ { for i := 0; i < Len; i++ {
src.Push(int2StrValue(i * i)) src.Push(int2StrValue(i * i))
} }
dest := src.Data() dest := src.Copy()
for i := 0; i < Len; i++ { for i := 0; i < Len; i++ {
src[i] = int2StrValue(-1) src[i] = int2StrValue(-1)
v := elem2StrValue(dest[i]) v := elem2StrValue(dest[i])
......
...@@ -104,8 +104,8 @@ func (p *Vector) Set(i int, x interface{}) { (*p)[i] = x } ...@@ -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] } func (p *Vector) Last() interface{} { return (*p)[len(*p)-1] }
// Data returns all the elements as a slice. // Copy makes a copy of the vector and returns it.
func (p *Vector) Data() []interface{} { func (p *Vector) Copy() Vector {
arr := make(Vector, len(*p)) arr := make(Vector, len(*p))
copy(arr, *p) copy(arr, *p)
return arr return arr
......
...@@ -326,14 +326,14 @@ func TestDo(t *testing.T) { ...@@ -326,14 +326,14 @@ func TestDo(t *testing.T) {
} }
func TestVectorData(t *testing.T) { func TestVectorCopy(t *testing.T) {
// verify Data() returns a slice of a copy, not a slice of the original vector // verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10 const Len = 10
var src Vector var src Vector
for i := 0; i < Len; i++ { for i := 0; i < Len; i++ {
src.Push(int2Value(i * i)) src.Push(int2Value(i * i))
} }
dest := src.Data() dest := src.Copy()
for i := 0; i < Len; i++ { for i := 0; i < Len; i++ {
src[i] = int2Value(-1) src[i] = int2Value(-1)
v := elem2Value(dest[i]) v := elem2Value(dest[i])
......
...@@ -39,11 +39,11 @@ func Any(iter Iterable, f func(interface{}) bool) bool { ...@@ -39,11 +39,11 @@ func Any(iter Iterable, f func(interface{}) bool) bool {
// Data returns a slice containing the elements of iter. // Data returns a slice containing the elements of iter.
func Data(iter Iterable) []interface{} { func Data(iter Iterable) []interface{} {
vec := new(vector.Vector) var v vector.Vector
for e := range iter.Iter() { 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 // filteredIterable is a struct that implements Iterable with each element
......
...@@ -371,7 +371,7 @@ func TestGroupBy(t *testing.T) { ...@@ -371,7 +371,7 @@ func TestGroupBy(t *testing.T) {
for x := range GroupBy(elevenToTwenty, intkey{}).Iter() { for x := range GroupBy(elevenToTwenty, intkey{}).Iter() {
out.Push(x.(Group).Key) out.Push(x.(Group).Key)
} }
assertArraysAreEqual(t, out.Data(), elevenToTwenty) assertArraysAreEqual(t, out, elevenToTwenty)
} }
func TestUnique(t *testing.T) { func TestUnique(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment