Documentation ¶
Overview ¶
Package arrayqueue implements a queue backed by array list.
Structure is not thread safe.
Reference: https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
Index ¶
- type Iterator
- func (iterator *Iterator[T]) Begin()
- func (iterator *Iterator[T]) End()
- func (iterator *Iterator[T]) First() bool
- func (iterator *Iterator[T]) Index() int
- func (iterator *Iterator[T]) Last() bool
- func (iterator *Iterator[T]) Next() bool
- func (iterator *Iterator[T]) NextTo(f func(index int, value T) bool) bool
- func (iterator *Iterator[T]) Prev() bool
- func (iterator *Iterator[T]) PrevTo(f func(index int, value T) bool) bool
- func (iterator *Iterator[T]) Value() T
- type Queue
- func (queue *Queue[T]) Clear()
- func (queue *Queue[T]) Dequeue() (value T, ok bool)
- func (queue *Queue[T]) Empty() bool
- func (queue *Queue[T]) Enqueue(value T)
- func (queue *Queue[T]) FromJSON(data []byte) error
- func (queue *Queue[T]) Iterator() *Iterator[T]
- func (queue *Queue[T]) MarshalJSON() ([]byte, error)
- func (queue *Queue[T]) Peek() (value T, ok bool)
- func (queue *Queue[T]) Size() int
- func (queue *Queue[T]) String() string
- func (queue *Queue[T]) ToJSON() ([]byte, error)
- func (queue *Queue[T]) UnmarshalJSON(bytes []byte) error
- func (queue *Queue[T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T comparable] struct { // contains filtered or unexported fields }
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Iterator[T]) Begin ¶
func (iterator *Iterator[T]) Begin()
Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.
func (*Iterator[T]) End ¶
func (iterator *Iterator[T]) End()
End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.
func (*Iterator[T]) 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[T]) Index ¶
Index returns the current element's index. Does not modify the state of the iterator.
func (*Iterator[T]) 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[T]) 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[T]) 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[T]) 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[T]) 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[T comparable] struct { // contains filtered or unexported fields }
Queue holds elements in an array-list
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]) Enqueue ¶
func (queue *Queue[T]) Enqueue(value T)
Enqueue adds a value to the end of the queue
func (*Queue[T]) Iterator ¶
Iterator returns a stateful iterator whose values can be fetched by an index.
func (*Queue[T]) MarshalJSON ¶
MarshalJSON @implements json.Marshaler
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