/ring

Generic circular buffer

Primary LanguageGoMIT LicenseMIT

Ring

test Go Reference

Generic circular buffer

Example

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]