Generic circular buffer
package main
import (
"fmt"
"github.com/WinPooh32/ring"
)
func main() {
const capacity = 9
data := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
ringBuf := ring.Make[int](capacity)
for _, v := range data {
elem, pop := ringBuf.Push(v)
if pop {
fmt.Println(elem)
}
}
l, r := ringBuf.TwoParts()
fmt.Println(l, r)
}
Output:
0
1
2
3
4
5
6
7
[8] [9 10 11 12 13 14 15 16]