Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
8d44052b
Commit
8d44052b
authored
Mar 23, 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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
src/lib/container/vector.go
src/lib/container/vector.go
+16
-0
src/lib/container/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) {
a
:=
p
.
a
;
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) {
verify_pattern
(
t
,
a
,
8
,
1000
,
2
);
}
func
TestSorting
(
t
*
testing
.
T
)
{
const
n
=
100
;
a
:=
vector
.
NewIntVector
(
n
);
...
...
@@ -170,3 +171,21 @@ func TestDo(t *testing.T) {
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