mirror of
https://github.com/golang/go
synced 2024-11-19 22:14:43 -07:00
container/vector: rename Data() -> Copy()
R=rsc CC=golang-dev https://golang.org/cl/1814043
This commit is contained in:
parent
1930cd5d38
commit
d9c47cd8c8
@ -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
|
||||
|
@ -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
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user