...
1
2
3
4
5 package ring_test
6
7 import (
8 "container/ring"
9 "fmt"
10 )
11
12 func ExampleRing_Len() {
13
14 r := ring.New(4)
15
16
17 fmt.Println(r.Len())
18
19
20
21 }
22
23 func ExampleRing_Next() {
24
25 r := ring.New(5)
26
27
28 n := r.Len()
29
30
31 for i := 0; i < n; i++ {
32 r.Value = i
33 r = r.Next()
34 }
35
36
37 for j := 0; j < n; j++ {
38 fmt.Println(r.Value)
39 r = r.Next()
40 }
41
42
43
44
45
46
47
48 }
49
50 func ExampleRing_Prev() {
51
52 r := ring.New(5)
53
54
55 n := r.Len()
56
57
58 for i := 0; i < n; i++ {
59 r.Value = i
60 r = r.Next()
61 }
62
63
64 for j := 0; j < n; j++ {
65 r = r.Prev()
66 fmt.Println(r.Value)
67 }
68
69
70
71
72
73
74
75 }
76
77 func ExampleRing_Do() {
78
79 r := ring.New(5)
80
81
82 n := r.Len()
83
84
85 for i := 0; i < n; i++ {
86 r.Value = i
87 r = r.Next()
88 }
89
90
91 r.Do(func(p interface{}) {
92 fmt.Println(p.(int))
93 })
94
95
96
97
98
99
100
101 }
102
103 func ExampleRing_Move() {
104
105 r := ring.New(5)
106
107
108 n := r.Len()
109
110
111 for i := 0; i < n; i++ {
112 r.Value = i
113 r = r.Next()
114 }
115
116
117 r = r.Move(3)
118
119
120 r.Do(func(p interface{}) {
121 fmt.Println(p.(int))
122 })
123
124
125
126
127
128
129
130 }
131
132 func ExampleRing_Link() {
133
134 r := ring.New(2)
135 s := ring.New(2)
136
137
138 lr := r.Len()
139 ls := s.Len()
140
141
142 for i := 0; i < lr; i++ {
143 r.Value = 0
144 r = r.Next()
145 }
146
147
148 for j := 0; j < ls; j++ {
149 s.Value = 1
150 s = s.Next()
151 }
152
153
154 rs := r.Link(s)
155
156
157 rs.Do(func(p interface{}) {
158 fmt.Println(p.(int))
159 })
160
161
162
163
164
165
166 }
167
168 func ExampleRing_Unlink() {
169
170 r := ring.New(6)
171
172
173 n := r.Len()
174
175
176 for i := 0; i < n; i++ {
177 r.Value = i
178 r = r.Next()
179 }
180
181
182 r.Unlink(3)
183
184
185 r.Do(func(p interface{}) {
186 fmt.Println(p.(int))
187 })
188
189
190
191
192
193 }
194
View as plain text