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 (iterator *Iterator) Begin()
- func (iterator *Iterator) End()
- func (iterator *Iterator) First() bool
- func (iterator *Iterator) Index() int
- func (iterator *Iterator) Last() bool
- func (iterator *Iterator) Next() bool
- func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Prev() bool
- func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool
- func (iterator *Iterator) Value() interface{}
- type Queue
- func (queue *Queue) Clear()
- func (queue *Queue) Dequeue() (value interface{}, ok bool)
- func (queue *Queue) Empty() bool
- func (queue *Queue) Enqueue(value interface{})
- func (queue *Queue) FromJSON(data []byte) error
- func (queue *Queue) Full() bool
- func (queue *Queue) Iterator() Iterator
- func (queue *Queue) MarshalJSON() ([]byte, error)
- func (queue *Queue) Peek() (value interface{}, ok bool)
- func (queue *Queue) Size() int
- func (queue *Queue) String() string
- func (queue *Queue) ToJSON() ([]byte, error)
- func (queue *Queue) UnmarshalJSON(bytes []byte) error
- func (queue *Queue) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Iterator) Begin ¶
func (iterator *Iterator) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator) End ¶
func (iterator *Iterator) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator) First ¶
First moves the iterator to the first element and returns true if there was a first element in the container. If First() returns true, then first element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator) Last ¶
Last moves the iterator to the last element and returns true if there was a last element in the container. If Last() returns true, then last element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Next ¶
Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.
func (*Iterator) NextTo ¶
NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) Prev ¶
Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
func (*Iterator) PrevTo ¶
PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.
type Queue ¶
type Queue 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 (*Queue) 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) Enqueue ¶
func (queue *Queue) Enqueue(value interface{})
Enqueue adds a value to the end of the queue
func (*Queue) Full ¶
Full returns true if the queue is full, i.e. has reached the maximum number of elements that it can hold.
func (*Queue) Iterator ¶
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Queue) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
func (*Queue) 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) UnmarshalJSON ¶
UnmarshalJSON @implements json.Unmarshaler