Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
8d44052b
Commit
8d44052b
authored
Mar 24, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iterator for vector
R=rsc DELTA=35 (35 added, 0 deleted, 0 changed) OCL=26662 CL=26662
parent
482cbb1f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
vector.go
src/lib/container/vector.go
+16
-0
vector_test.go
src/lib/container/vector_test.go
+19
-0
No files found.
src/lib/container/vector.go
View file @
8d44052b
...
@@ -210,3 +210,19 @@ func (p *Vector) Swap(i, j int) {
...
@@ -210,3 +210,19 @@ func (p *Vector) Swap(i, j int) {
a
:=
p
.
a
;
a
:=
p
.
a
;
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
}
}
// Iterate over all elements; driver for range
func
(
p
*
Vector
)
iterate
(
c
chan
Element
)
{
for
i
:=
0
;
i
<
len
(
p
.
a
);
i
++
{
c
<-
p
.
a
[
i
]
}
close
(
c
);
}
// Channel iterator for range.
func
(
p
*
Vector
)
Iter
()
chan
Element
{
c
:=
make
(
chan
Element
);
go
p
.
iterate
(
c
);
return
c
;
}
src/lib/container/vector_test.go
View file @
8d44052b
...
@@ -139,6 +139,7 @@ func TestInsertVector(t *testing.T) {
...
@@ -139,6 +139,7 @@ func TestInsertVector(t *testing.T) {
verify_pattern
(
t
,
a
,
8
,
1000
,
2
);
verify_pattern
(
t
,
a
,
8
,
1000
,
2
);
}
}
func
TestSorting
(
t
*
testing
.
T
)
{
func
TestSorting
(
t
*
testing
.
T
)
{
const
n
=
100
;
const
n
=
100
;
a
:=
vector
.
NewIntVector
(
n
);
a
:=
vector
.
NewIntVector
(
n
);
...
@@ -170,3 +171,21 @@ func TestDo(t *testing.T) {
...
@@ -170,3 +171,21 @@ func TestDo(t *testing.T) {
t
.
Error
(
"should visit"
,
n
,
"values; did visit"
,
count
)
t
.
Error
(
"should visit"
,
n
,
"values; did visit"
,
count
)
}
}
}
}
func
TestIter
(
t
*
testing
.
T
)
{
const
Len
=
100
;
x
:=
vector
.
New
(
Len
);
for
i
:=
0
;
i
<
Len
;
i
++
{
x
.
Set
(
i
,
i
*
i
);
}
i
:=
0
;
for
v
:=
range
x
.
Iter
()
{
if
v
.
(
int
)
!=
i
*
i
{
t
.
Error
(
"Iter expected"
,
i
*
i
,
"got"
,
v
.
(
int
))
}
i
++
;
}
if
i
!=
Len
{
t
.
Error
(
"Iter stopped at"
,
i
,
"not"
,
Len
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment