
Simple ringbuffer
Simple thread-free ringbuffer implement by golang
install
go get github.com/Noahnut/ringbuffer
Ringbuffer struct
type ringbuff struct {
ringbufferArray []interface{}
size int
front int
rear int
len int
mux *sync.RWMutex
}
Enqueu
add element to the ringbuffer
if ringbuffer is full return false
func (this *ringbuff) Enqueue(value interface{}) bool
Dequeue
delete element from the ringbuffer
if ringbuffer is empty return false
func (this *ringbuff) Dequeue() bool
GetFront
get the top element on the queue
if the queue is empty return nil
func (this *ringbuff) GetFront() interface{}
GetRear
get the last element on the queue
if the queue is empty return nil
func (this *ringbuff) GetRear() interface{}
IsEmpty
check the ringbuffer is empty or not
if is empty return true
func (this *ringbuff) IsEmpty() bool
IsFull
check the ringbuffer is full or not
if is empty return true
func (this *ringbuff) IsFull() bool