package graph

type RingBuffer struct {
	data []float64
	size int
	idx  int
	full bool
}

func New(size int) *RingBuffer {
	return &RingBuffer{data: make([]float64, size), size: size}
}

func (r *RingBuffer) Add(v float64) {
	r.data[r.idx] = v
	r.idx = (r.idx + 1) % r.size
	if r.idx == 0 {
		r.full = true
	}
}

func (r *RingBuffer) Values() []float64 {
	if !r.full {
		return r.data[:r.idx]
	}
	return append(r.data[r.idx:], r.data[:r.idx]...)
}