Documentation
¶
Overview ¶
Package ringbuffer provides a simple implementation of a fixed size ring buffer.
Index ¶
- type RingBuffer
- func (rb *RingBuffer) Capacity() int
- func (rb *RingBuffer) Clear()
- func (rb *RingBuffer) IsEmpty() bool
- func (rb *RingBuffer) IsFull() bool
- func (rb *RingBuffer) Length() int
- func (rb *RingBuffer) Peek() interface{}
- func (rb *RingBuffer) Read() interface{}
- func (rb *RingBuffer) ReadAt(i int) interface{}
- func (rb *RingBuffer) Write(v interface{})
- func (rb *RingBuffer) WriteAt(i int, v interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a fixed size ring buffer.
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
NewRingBuffer creates a new buffer of a given size.
func (*RingBuffer) Capacity ¶
func (rb *RingBuffer) Capacity() int
Capacity returns the current capacity of the ring buffer.
func (*RingBuffer) IsEmpty ¶
func (rb *RingBuffer) IsEmpty() bool
IsEmpty checks if the ring buffer is empty
func (*RingBuffer) IsFull ¶
func (rb *RingBuffer) IsFull() bool
IsFull checks if the ring buffer is full
func (*RingBuffer) Length ¶
func (rb *RingBuffer) Length() int
Length returns the element counts inside the ring buffer.
func (*RingBuffer) Peek ¶
func (rb *RingBuffer) Peek() interface{}
Peek peek the reader element and not affect the index
func (*RingBuffer) Read ¶
func (rb *RingBuffer) Read() interface{}
Read read an element from the ring buffer, nil if empty
func (*RingBuffer) ReadAt ¶
func (rb *RingBuffer) ReadAt(i int) interface{}
ReadAt read an element at index i, i could be negative
func (*RingBuffer) Write ¶
func (rb *RingBuffer) Write(v interface{})
Write an element into the ring buffer
func (*RingBuffer) WriteAt ¶
func (rb *RingBuffer) WriteAt(i int, v interface{})
WriteAt write an element at index i, i could be negative