Skip to content

simple thread-free ringbuffer implement by golang

License

Notifications You must be signed in to change notification settings

Noahnut/ringbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT Build Status

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