Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrIsEmpty = errors.New("ringbuffer is empty")
Functions ¶
This section is empty.
Types ¶
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
https://github.com/smallnest/chanx/blob/main/ringbuffer.go http://media.newbmiao.com//algorithm/ringbuffer.png RingBuffer is a ring buffer for common types. It never is full and always grows if it will be full. It is not thread-safe(goroutine-safe) so you must use the lock-like synchronization primitive to use it in multiple writers and multiple readers.
func NewRingBuffer ¶
func NewRingBuffer(initialSize int) *RingBuffer
func (*RingBuffer) Capacity ¶
func (r *RingBuffer) Capacity() int
Capacity returns the size of the underlying buffer.
func (*RingBuffer) IsEmpty ¶
func (r *RingBuffer) IsEmpty() bool
func (*RingBuffer) Len ¶
func (r *RingBuffer) Len() int
func (*RingBuffer) Peek ¶
func (r *RingBuffer) Peek() T
func (*RingBuffer) Pop ¶
func (r *RingBuffer) Pop() T
func (*RingBuffer) Read ¶
func (r *RingBuffer) Read() (T, error)
func (*RingBuffer) Reset ¶
func (r *RingBuffer) Reset()
func (*RingBuffer) Write ¶
func (r *RingBuffer) Write(v T)
Click to show internal directories.
Click to hide internal directories.