package door import "log" type FIFOBuffer[T any] struct { data []T index int } func NewFIFOBuffer[T any](maxsize int) FIFOBuffer[T] { return FIFOBuffer[T]{data: make([]T, maxsize)} } func (f *FIFOBuffer[T]) Empty() bool { return f.index == 0 } func (f *FIFOBuffer[T]) Push(value T) { if f.index >= len(f.data) { log.Panicf("Exceeded FIFOBuffer index %d size %d %#v", f.index, len(f.data), f.data) } f.data[f.index] = value f.index++ } func (f *FIFOBuffer[T]) Pop() T { if f.index == 0 { log.Panicf("Pop from empty FIFOBuffer (size %d).", len(f.data)) } f.index-- return f.data[f.index] }