func printRing(r *ring.Ring) { elements := make([]interface{}, 0, r.Len()) r.Do(func(i interface{}) { elements = append(elements, i) }) log.Printf("%v", elements) }
func slicifyRing(r *ring.Ring) { l := r.Len() s := make([]WindowData, 0, l) for i := 0; i < l; i++ { s = append(s, r.Value.(WindowData)) r = r.Prev() } }
func slicifyRing(r *ring.Ring) { l := r.Len() s := make([]float64, 0, l) for i := 0; i < l; i++ { s = append(s, r.Value.(float64)) r = r.Prev() } }
func current_extremes(r *ring.Ring) (int, int) { length := r.Len() if length%2 != 0 { fmt.Fprintln(os.Stderr, "error: Ring must be even") os.Exit(1) } fmt.Println(r.Value) return r.Value.(int), r.Move(length / 2).Value.(int) }
func RingToStringInt64(r *ring.Ring, delim string, delta bool) string { bb := new(bytes.Buffer) prev := r.Value.(int64) r = r.Next() for i := 1; i < r.Len(); i++ { if delta { if r.Value.(int64) == int64(0) { bb.WriteString(fmt.Sprintf("0%s", delim)) } else { d := r.Value.(int64) - prev bb.WriteString(fmt.Sprintf("%d%s", d, delim)) } prev = r.Value.(int64) } else { bb.WriteString(fmt.Sprintf("%d%s", r.Value.(int64), delim)) } r = r.Next() } return strings.TrimSuffix(bb.String(), delim) }