Commit 345f9c9e authored by Robert Griesemer's avatar Robert Griesemer

container/vector: remove Iter() from interface

(Iter() is almost never the right mechanism to call.
Per discussion with rsc.)

R=rsc
CC=golang-dev
https://golang.org/cl/1771043
parent 89192ce4
...@@ -42,7 +42,6 @@ generate: vector.go vector_test.go ...@@ -42,7 +42,6 @@ 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='TestIter -> TestIntIter'\
| gofmt -r='TestVectorData -> TestIntVectorData'\ | gofmt -r='TestVectorData -> TestIntVectorData'\
| gofmt -r='interface{} -> int'\ | gofmt -r='interface{} -> int'\
> intvector_test.go\ > intvector_test.go\
...@@ -65,7 +64,6 @@ generate: vector.go vector_test.go ...@@ -65,7 +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='TestIter -> TestStrIter'\
| gofmt -r='TestVectorData -> TestStrVectorData'\ | gofmt -r='TestVectorData -> TestStrVectorData'\
| gofmt -r='interface{} -> string'\ | gofmt -r='interface{} -> string'\
> stringvector_test.go > stringvector_test.go
...@@ -199,23 +199,6 @@ func (p *IntVector) Swap(i, j int) { ...@@ -199,23 +199,6 @@ func (p *IntVector) Swap(i, j int) {
} }
// Iterate over all elements; driver for range
func (p *IntVector) iterate(c chan<- int) {
for _, v := range *p {
c <- v
}
close(c)
}
// Channel iterator for range.
func (p *IntVector) Iter() <-chan int {
c := make(chan int)
go p.iterate(c)
return c
}
// Do calls function f for each element of the vector, in order. // Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p. // The behavior of Do is undefined if f changes *p.
func (p *IntVector) Do(f func(elem int)) { func (p *IntVector) Do(f func(elem int)) {
......
...@@ -326,53 +326,6 @@ func TestIntDo(t *testing.T) { ...@@ -326,53 +326,6 @@ func TestIntDo(t *testing.T) {
} }
func TestIntIter(t *testing.T) {
const Len = 100
x := new(IntVector).Resize(Len, 0)
for i := 0; i < Len; i++ {
x.Set(i, int2IntValue(i*i))
}
i := 0
for v := range x.Iter() {
if elem2IntValue(v) != int2IntValue(i*i) {
t.Error(tname(x), "Iter expected", i*i, "got", elem2IntValue(v))
}
i++
}
if i != Len {
t.Error(tname(x), "Iter stopped at", i, "not", Len)
}
y := new(IntVector).Resize(Len, 0)
for i := 0; i < Len; i++ {
(*y)[i] = int2IntValue(i * i)
}
i = 0
for v := range y.Iter() {
if elem2IntValue(v) != int2IntValue(i*i) {
t.Error(tname(y), "y, Iter expected", i*i, "got", elem2IntValue(v))
}
i++
}
if i != Len {
t.Error(tname(y), "y, Iter stopped at", i, "not", Len)
}
var z IntVector
z.Resize(Len, 0)
for i := 0; i < Len; i++ {
z[i] = int2IntValue(i * i)
}
i = 0
for v := range z.Iter() {
if elem2IntValue(v) != int2IntValue(i*i) {
t.Error(tname(z), "z, Iter expected", i*i, "got", elem2IntValue(v))
}
i++
}
if i != Len {
t.Error(tname(z), "z, Iter stopped at", i, "not", Len)
}
}
func TestIntVectorData(t *testing.T) { func TestIntVectorData(t *testing.T) {
// verify Data() returns a slice of a copy, not a slice of the original vector // verify Data() returns a slice of a copy, not a slice of the original vector
const Len = 10 const Len = 10
......
...@@ -199,23 +199,6 @@ func (p *StringVector) Swap(i, j int) { ...@@ -199,23 +199,6 @@ func (p *StringVector) Swap(i, j int) {
} }
// Iterate over all elements; driver for range
func (p *StringVector) iterate(c chan<- string) {
for _, v := range *p {
c <- v
}
close(c)
}
// Channel iterator for range.
func (p *StringVector) Iter() <-chan string {
c := make(chan string)
go p.iterate(c)
return c
}
// Do calls function f for each element of the vector, in order. // Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p. // The behavior of Do is undefined if f changes *p.
func (p *StringVector) Do(f func(elem string)) { func (p *StringVector) Do(f func(elem string)) {
......
...@@ -326,53 +326,6 @@ func TestStrDo(t *testing.T) { ...@@ -326,53 +326,6 @@ func TestStrDo(t *testing.T) {
} }
func TestStrIter(t *testing.T) {
const Len = 100
x := new(StringVector).Resize(Len, 0)
for i := 0; i < Len; i++ {
x.Set(i, int2StrValue(i*i))
}
i := 0
for v := range x.Iter() {
if elem2StrValue(v) != int2StrValue(i*i) {
t.Error(tname(x), "Iter expected", i*i, "got", elem2StrValue(v))
}
i++
}
if i != Len {
t.Error(tname(x), "Iter stopped at", i, "not", Len)
}
y := new(StringVector).Resize(Len, 0)
for i := 0; i < Len; i++ {
(*y)[i] = int2StrValue(i * i)
}
i = 0
for v := range y.Iter() {
if elem2StrValue(v) != int2StrValue(i*i) {
t.Error(tname(y), "y, Iter expected", i*i, "got", elem2StrValue(v))
}
i++
}
if i != Len {
t.Error(tname(y), "y, Iter stopped at", i, "not", Len)
}
var z StringVector
z.Resize(Len, 0)
for i := 0; i < Len; i++ {
z[i] = int2StrValue(i * i)
}
i = 0
for v := range z.Iter() {
if elem2StrValue(v) != int2StrValue(i*i) {
t.Error(tname(z), "z, Iter expected", i*i, "got", elem2StrValue(v))
}
i++
}
if i != Len {
t.Error(tname(z), "z, Iter stopped at", i, "not", Len)
}
}
func TestStrVectorData(t *testing.T) { func TestStrVectorData(t *testing.T) {
// verify Data() returns a slice of a copy, not a slice of the original vector // verify Data() returns a slice of a copy, not a slice of the original vector
const Len = 10 const Len = 10
......
...@@ -199,23 +199,6 @@ func (p *Vector) Swap(i, j int) { ...@@ -199,23 +199,6 @@ func (p *Vector) Swap(i, j int) {
} }
// Iterate over all elements; driver for range
func (p *Vector) iterate(c chan<- interface{}) {
for _, v := range *p {
c <- v
}
close(c)
}
// Channel iterator for range.
func (p *Vector) Iter() <-chan interface{} {
c := make(chan interface{})
go p.iterate(c)
return c
}
// Do calls function f for each element of the vector, in order. // Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p. // The behavior of Do is undefined if f changes *p.
func (p *Vector) Do(f func(elem interface{})) { func (p *Vector) Do(f func(elem interface{})) {
......
...@@ -326,53 +326,6 @@ func TestDo(t *testing.T) { ...@@ -326,53 +326,6 @@ func TestDo(t *testing.T) {
} }
func TestIter(t *testing.T) {
const Len = 100
x := new(Vector).Resize(Len, 0)
for i := 0; i < Len; i++ {
x.Set(i, int2Value(i*i))
}
i := 0
for v := range x.Iter() {
if elem2Value(v) != int2Value(i*i) {
t.Error(tname(x), "Iter expected", i*i, "got", elem2Value(v))
}
i++
}
if i != Len {
t.Error(tname(x), "Iter stopped at", i, "not", Len)
}
y := new(Vector).Resize(Len, 0)
for i := 0; i < Len; i++ {
(*y)[i] = int2Value(i * i)
}
i = 0
for v := range y.Iter() {
if elem2Value(v) != int2Value(i*i) {
t.Error(tname(y), "y, Iter expected", i*i, "got", elem2Value(v))
}
i++
}
if i != Len {
t.Error(tname(y), "y, Iter stopped at", i, "not", Len)
}
var z Vector
z.Resize(Len, 0)
for i := 0; i < Len; i++ {
z[i] = int2Value(i * i)
}
i = 0
for v := range z.Iter() {
if elem2Value(v) != int2Value(i*i) {
t.Error(tname(z), "z, Iter expected", i*i, "got", elem2Value(v))
}
i++
}
if i != Len {
t.Error(tname(z), "z, Iter stopped at", i, "not", Len)
}
}
func TestVectorData(t *testing.T) { func TestVectorData(t *testing.T) {
// verify Data() returns a slice of a copy, not a slice of the original vector // verify Data() returns a slice of a copy, not a slice of the original vector
const Len = 10 const Len = 10
......
...@@ -361,10 +361,8 @@ func parseGroups(lines []string) ([]Group, os.Error) { ...@@ -361,10 +361,8 @@ func parseGroups(lines []string) ([]Group, os.Error) {
res.Push(&Group{ss[0], high, low, ss[3]}) res.Push(&Group{ss[0], high, low, ss[3]})
} }
realres := make([]Group, res.Len()) realres := make([]Group, res.Len())
i := 0 for i, v := range res {
for v := range res.Iter() {
realres[i] = *v.(*Group) realres[i] = *v.(*Group)
i++
} }
return realres, nil return realres, nil
} }
......
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