Golang container/ring.Ring.Link() function example
package container/ring
See http://golang.org/pkg/container/ring/#Ring.Link description for further explanation how Link works.
Golang container/ring.Ring.Link() function usage example
package main
import (
"container/ring"
"fmt"
)
func main() {
r := ring.New(10)
// populate our ring
for i := 0; i < 10; i++ {
r.Value = i
r = r.Next()
}
r2 := ring.New(10)
// populate our ring
for t := 0; t < 10; t++ {
r2.Value = t
r2 = r2.Next()
}
f := func(v interface{}) {
fmt.Printf("%d ", v)
}
// Values in r before link
fmt.Println("Values in r BEFORE link")
r.Do(f)
fmt.Println()
r.Link(r2)
// Values in r AFTER link
fmt.Println("Values in r AFTER link")
r.Do(f)
fmt.Println()
}
Output :
Values in r BEFORE link
0 1 2 3 4 5 6 7 8 9
Values in r AFTER link
0 0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Reference :
Advertisement
Something interesting
Tutorials
+11.6k Golang : Surveillance with web camera and OpenCV
+10.9k Golang : Sieve of Eratosthenes algorithm
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+8.1k Golang : Check from web if Go application is running or not
+11.3k Golang : Post data with url.Values{}
+13.9k Golang : How to check if a file is hidden?
+18.5k Golang : Aligning strings to right, left and center with fill example
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+9.4k Golang : Qt Yes No and Quit message box example
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error