Skip to content

Commit a3b67be

Browse files
authored
Merge pull request #2 from cryptography-research-lab/dev
添加迭代器示例代码 & 更新文档
2 parents 8549044 + 1c7c77d commit a3b67be

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func main() {
115115

116116
## 3.5 迭代器模式
117117

118-
`CycleString`有一个迭代器模式的实现`CycleStringIterator`,通过`Iterator`方法来获取:
118+
`CycleString`有两个迭代器模式的实现`CycleStringByteIterator``CycleStringRuneIterator`,通过`ByteIterator``RuneIterator`方法来获取:
119119

120120
```go
121121
package main
@@ -129,15 +129,16 @@ import (
129129
func main() {
130130

131131
cycleString := cycle_string.NewCycleString("CC11001100")
132-
iterator := cycleString.Iterator()
132+
iterator := cycleString.RuneIterator()
133+
134+
fmt.Println(string(iterator.NextN(3)))
135+
133136
for iterator.Next() {
134137
fmt.Println(string(iterator.Value()))
135138
time.Sleep(time.Millisecond * 100)
136139
}
137140
// Output:
138-
// C
139-
// C
140-
// 1
141+
// CC1
141142
// 1
142143
// 0
143144
// 0

examples/iterator/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import (
99
func main() {
1010

1111
cycleString := cycle_string.NewCycleString("CC11001100")
12-
iterator := cycleString.Iterator()
12+
iterator := cycleString.RuneIterator()
13+
14+
fmt.Println(string(iterator.NextN(3)))
15+
1316
for iterator.Next() {
1417
fmt.Println(string(iterator.Value()))
1518
time.Sleep(time.Millisecond * 100)
1619
}
1720
// Output:
18-
// C
19-
// C
20-
// 1
21+
// CC1
2122
// 1
2223
// 0
2324
// 0

0 commit comments

Comments
 (0)