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
+7k Golang : Levenshtein distance example
+6.2k Golang & Javascript : How to save cropped image to file on server
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+11.6k Golang : Convert(cast) float to int
+17k Golang : XML to JSON example
+28.7k Golang : Detect (OS) Operating System
+7.5k Golang : Rename part of filename
+6.5k Elasticsearch : Shutdown a local node
+19.2k Golang : Check if directory exist and create if does not exist
+5.6k PHP : Convert CSV to JSON with YQL example
+5.8k Golang : Markov chains to predict probability of next state example
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters