Skip to content

WinPooh32/ring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]