Documentation
¶
Overview ¶
Package circularbuffer implements the circular buffer.
In computer science, a circular buffer, circular queue, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.
Structure is not thread safe.
Index ¶
- type Iterator
- func (it *Iterator[T]) DistanceTo(other ds.OrderedIterator) int
- func (it *Iterator[T]) Get() (value T, found bool)
- func (it *Iterator[T]) GetAt(i int) (value T, found bool)
- func (it *Iterator[T]) GetAtKey(i int) (value T, found bool)
- func (it *Iterator[T]) GetKey() (int, bool)
- func (it *Iterator[T]) Index() (int, bool)
- func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
- func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
- func (it *Iterator[T]) IsBegin() bool
- func (it *Iterator[T]) IsEnd() bool
- func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool
- func (it *Iterator[T]) IsFirst() bool
- func (it *Iterator[T]) IsLast() bool
- func (it *Iterator[T]) IsValid() bool
- func (it *Iterator[T]) MoveBy(n int) bool
- func (it *Iterator[T]) MoveTo(i int) bool
- func (it *Iterator[T]) MoveToKey(i int) bool
- func (it *Iterator[T]) Next() bool
- func (it *Iterator[T]) NextN(i int) bool
- func (it *Iterator[T]) Previous() bool
- func (it *Iterator[T]) PreviousN(n int) bool
- func (it *Iterator[T]) Set(value T) bool
- func (it *Iterator[T]) SetAt(i int, value T) bool
- func (it *Iterator[T]) SetAtKey(i int, value T) bool
- func (it *Iterator[T]) Size() int
- type Queue
- func (queue *Queue[T]) Begin() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (queue *Queue[T]) Clear()
- func (queue *Queue[T]) Dequeue() (value T, ok bool)
- func (queue *Queue[T]) End() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (queue *Queue[T]) Enqueue(value T)
- func (queue *Queue[T]) First() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (queue *Queue[T]) FromJSON(data []byte) error
- func (queue *Queue[T]) Full() bool
- func (queue *Queue[T]) GetValues() []T
- func (queue *Queue[T]) IsEmpty() bool
- func (queue *Queue[T]) Last() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
- func (queue *Queue[T]) MarshalJSON() ([]byte, error)
- func (list *Queue[T]) NewIterator(index int, size int) *Iterator[T]
- func (queue *Queue[T]) Peek() (value T, ok bool)
- func (queue *Queue[T]) Size() int
- func (queue *Queue[T]) ToJSON() ([]byte, error)
- func (queue *Queue[T]) ToString() string
- func (queue *Queue[T]) UnmarshalJSON(bytes []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T any] struct { // contains filtered or unexported fields }
Iterator holding the iterator's state
func (*Iterator[T]) DistanceTo ¶ added in v0.15.0
func (it *Iterator[T]) DistanceTo(other ds.OrderedIterator) int
If other is of type IndexedIterator, IndexedIterator.Index() will be used, possibly executing in O(1)
func (*Iterator[T]) IsAfter ¶ added in v0.15.0
func (it *Iterator[T]) IsAfter(other ds.OrderedIterator) bool
func (*Iterator[T]) IsBefore ¶ added in v0.15.0
func (it *Iterator[T]) IsBefore(other ds.OrderedIterator) bool
func (*Iterator[T]) IsEqual ¶ added in v0.15.0
func (it *Iterator[T]) IsEqual(other ds.ComparableIterator) bool
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue holds values in a slice.
func New ¶
New instantiates a new empty queue with the specified size of maximum number of elements that it can hold. This max size of the buffer cannot be changed.
func NewFromIterator ¶ added in v0.15.0
func NewFromIterator[T any](maxSize int, begin ds.ReadForIterator[T]) *Queue[T]
NewFromIterator instantiates a new queue containing the elements provided by the passed iterator.
func NewFromIterators ¶ added in v0.15.0
func NewFromIterators[T any](maxSize int, begin ds.ReadCompForIterator[T], end ds.ComparableIterator) *Queue[T]
NewFromIterators instantiates a new queue containing the elements provided by first, until it is equal to end. end is a sentinel and not included.
func NewFromSlice ¶ added in v0.15.0
func (*Queue[T]) Begin ¶ added in v0.15.0
func (queue *Queue[T]) Begin() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
Begin returns an initialized iterator, which points to one element before it's first. Unless Next() is called, the iterator is in an invalid state.
func (*Queue[T]) Dequeue ¶
Dequeue removes first element of the queue and returns it, or nil if queue is empty. Second return parameter is true, unless the queue was empty and there was nothing to dequeue.
func (*Queue[T]) End ¶ added in v0.15.0
func (queue *Queue[T]) End() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
End returns an initialized iterator, which points to one element afrer it's last. Unless Previous() is called, the iterator is in an invalid state.
func (*Queue[T]) Enqueue ¶
func (queue *Queue[T]) Enqueue(value T)
Enqueue adds a value to the end of the queue
func (*Queue[T]) First ¶ added in v0.15.0
func (queue *Queue[T]) First() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
First returns an initialized iterator, which points to it's first element.
func (*Queue[T]) Full ¶
Full returns true if the queue is full, i.e. has reached the maximum number of elements that it can hold.
func (*Queue[T]) GetValues ¶ added in v0.3.0
func (queue *Queue[T]) GetValues() []T
Values returns all elements in the queue (FIFO order).
func (*Queue[T]) IsEmpty ¶ added in v0.3.0
Empty returns true if queue does not contain any elements.
func (*Queue[T]) Last ¶ added in v0.15.0
func (queue *Queue[T]) Last() ds.ReadWriteOrdCompBidRandCollIterator[int, T]
Last returns an initialized iterator, which points to it's last element.
func (*Queue[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Queue[T]) NewIterator ¶ added in v0.15.0
NewIterator returns a stateful iterator whose values can be fetched by an index.
func (*Queue[T]) Peek ¶
Peek returns first element of the queue without removing it, or nil if queue is empty. Second return parameter is true, unless the queue was empty and there was nothing to peek.
func (*Queue[T]) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler