Documentation
¶
Index ¶
- type CircularBuffer
- func (cb *CircularBuffer[E]) Clear()
- func (cb *CircularBuffer[E]) Clone() *CircularBuffer[E]
- func (cb *CircularBuffer[E]) Dequeue() (E, bool)
- func (cb *CircularBuffer[E]) Enqueue(e E) bool
- func (cb *CircularBuffer[E]) IsEmpty() bool
- func (cb *CircularBuffer[E]) IsFull() bool
- func (cb *CircularBuffer[E]) Len() int
- func (cb *CircularBuffer[E]) MarshalJSON() ([]byte, error)
- func (cb *CircularBuffer[E]) Peek() (E, bool)
- func (cb *CircularBuffer[E]) Range(fn func(e E) bool)
- func (cb *CircularBuffer[E]) Slice() []E
- func (cb *CircularBuffer[E]) String() string
- func (cb *CircularBuffer[E]) UnmarshalJSON(data []byte) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircularBuffer ¶
type CircularBuffer[E any] struct { // contains filtered or unexported fields }
CircularBuffer represents a generic circular buffer implementation. It supports thread-safe operations and can be configured to either drop new data or overwrite old data when the buffer is full.
func New ¶
func New[E any](size int, ops ...Option[E]) (*CircularBuffer[E], error)
New creates a new circular buffer with the specified size.
func NewFromSlice ¶
func NewFromSlice[E any](slice []E, ops ...Option[E]) (*CircularBuffer[E], error)
NewFromSlice creates a new circular buffer initialized with the given slice. The buffer size will be equal to the length of the slice and will contain all elements from the slice.
func (*CircularBuffer[E]) Clear ¶
func (cb *CircularBuffer[E]) Clear()
Clear removes all elements from the CircularBuffer.
func (*CircularBuffer[E]) Clone ¶
func (cb *CircularBuffer[E]) Clone() *CircularBuffer[E]
Clone returns a copy of the CircularBuffer.
func (*CircularBuffer[E]) Dequeue ¶
func (cb *CircularBuffer[E]) Dequeue() (E, bool)
Dequeue removes an element from the CircularBuffer. Returns zero value and false if the buffer is empty, otherwise the element and true.
func (*CircularBuffer[E]) Enqueue ¶
func (cb *CircularBuffer[E]) Enqueue(e E) bool
Enqueue adds an element to the CircularBuffer. Returns false if the buffer is full, otherwise true.
func (*CircularBuffer[E]) IsEmpty ¶
func (cb *CircularBuffer[E]) IsEmpty() bool
IsEmpty reports whether the CircularBuffer is empty.
func (*CircularBuffer[E]) IsFull ¶
func (cb *CircularBuffer[E]) IsFull() bool
IsFull reports whether the CircularBuffer is full.
func (*CircularBuffer[E]) Len ¶
func (cb *CircularBuffer[E]) Len() int
Len returns the number of elements in the CircularBuffer.
func (*CircularBuffer[E]) MarshalJSON ¶
func (cb *CircularBuffer[E]) MarshalJSON() ([]byte, error)
func (*CircularBuffer[E]) Peek ¶
func (cb *CircularBuffer[E]) Peek() (E, bool)
Peek returns the first element in the CircularBuffer without removing it. Returns zero value and false if the buffer is empty, otherwise the element and true.
func (*CircularBuffer[E]) Range ¶
func (cb *CircularBuffer[E]) Range(fn func(e E) bool)
Range calls "fn" for each element in the CircularBuffer. function "fn" returns false to stop the iteration.
func (*CircularBuffer[E]) Slice ¶
func (cb *CircularBuffer[E]) Slice() []E
Slice returns a slice of all elements in the CircularBuffer. It returns empty slice(not nil) if the CircularBuffer is empty.
func (*CircularBuffer[E]) String ¶
func (cb *CircularBuffer[E]) String() string
String returns a string representation of the CircularBuffer.
func (*CircularBuffer[E]) UnmarshalJSON ¶
func (cb *CircularBuffer[E]) UnmarshalJSON(data []byte) error