Golang container/ring.Ring.Unlink() function example
package container/ring
Unlink removes n (1st parameter) elements from the ring r, starting at r.Next(). If n is not found, the ring r remains unchanged. The result is the removed subring. Before unlink operation on the ring r. The ring r must not be empty.
Golang container/ring.Ring.Unlink() function usage example
package main
import (
"container/ring"
"fmt"
)
func main() {
r := ring.New(10)
// populate our ring
for i := 10; i > 0; i-- {
r.Value = i
r = r.Prev() // Prev element to populate
}
fmt.Printf("%d ", r.Value)
reverse := r.Prev()
for ; reverse != r; reverse = reverse.Prev() {
fmt.Printf("%d ", reverse.Value)
}
fmt.Println()
r.Unlink(6)
fmt.Printf("%d ", r.Value)
reverse = r.Prev()
for ; reverse != r; reverse = reverse.Prev() {
fmt.Printf("%d ", reverse.Value)
}
fmt.Println()
}
Output :
Before Unlink :
10 9 8 7 6 5 4 3 2 1
After Unlink :
10 9 8 7
Reference :
Advertisement
Something interesting
Tutorials
+9.8k Golang : Qt get screen resolution and display on center example
+19.2k Golang : Check whether a network interface is up on your machine
+4.7k JavaScript: Add marker function on Google Map
+17.4k Golang : Multi threading or run two processes or more example
+12.1k Golang : Pagination with go-paginator configuration example
+8.8k Android Studio : Image button and button example
+30.4k Golang : Generate random string
+17k Golang : Get number of CPU cores
+10.2k Golang : Random Rune generator
+35.1k Golang : Upload and download file to/from AWS S3
+11.6k Golang : Display a text file line by line with line number example
+5.3k Golang : Pad file extension automagically