circularqueue

package
v0.0.0-...-2a10efc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnumerableWithIndex

type EnumerableWithIndex[T comparable] interface {
	// Filter returns a new container containing all elements for which the given function returns a true value.
	Filter(func(index int, value T) bool) *Queue[T]

	containers.EnumerableWithIndex[T]
}

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator is the structure used to iterate over a queue.

func (*Iterator[T]) Begin

func (it *Iterator[T]) Begin()

Begin resets the iterator to its initial state.

func (*Iterator[T]) End

func (it *Iterator[T]) End()

End moves the iterator past the last element of the collection.

func (*Iterator[T]) First

func (it *Iterator[T]) First() bool

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

func (it *Iterator[T]) Index() int

Index returns the current index of the iterator.

func (*Iterator[T]) Last

func (it *Iterator[T]) Last() bool

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

func (it *Iterator[T]) Next() bool

Next returns true if there are more elements to iterate over.

func (*Iterator[T]) Prev

func (it *Iterator[T]) Prev() bool

Prev returns true if there are more elements to iterate over.

func (*Iterator[T]) Value

func (it *Iterator[T]) Value() T

Value returns the current element of the iterator.

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue holds the value of sice. Circular queue: The queue is implemented as a ring buffer. The size of the queue is fixed. The queue is full when the end is equal to the start. The queue is empty when the end is equal to the start and the queue is not full. see: https://en.wikipedia.org/wiki/Circular_buffer

func Map

func Map[K any, V any](q *Queue[K], f func(index int, value K) V) *Queue[V]

Map invokes the given function once for each element and returns a container containing the values returned by the given function.

func New

func New[T any](maxSize int) *Queue[T]

New creates a new queue.

func (*Queue[T]) All

func (q *Queue[T]) All(f func(index int, value T) bool) bool

All passes each element of the container to the given function and returns true if the function returns true for all elements.

func (*Queue[T]) Any

func (q *Queue[T]) Any(f func(index int, value T) bool) bool

Any passes each element of the container to the given function and returns true if the function ever returns true for any element.

func (*Queue[T]) Clear

func (q *Queue[T]) Clear()

Clear removes all values from the queue.

func (*Queue[T]) Dequeue

func (q *Queue[T]) Dequeue() (_ T, _ bool)

Dequeue removes the first value from the queue.

func (*Queue[T]) Each

func (q *Queue[T]) Each(f func(index int, value T))

Each calls the given function once for each element, passing that element's index and value.

func (*Queue[T]) Empty

func (q *Queue[T]) Empty() bool

Empty returns true if the queue is empty.

func (*Queue[T]) Enqueue

func (q *Queue[T]) Enqueue(value T)

Enqueue adds a new value to the queue. if the queue is full, it will remove the first element in the front of the queue.

func (*Queue[T]) Filter

func (q *Queue[T]) Filter(f func(index int, value T) bool) *Queue[T]

Filter returns a new container containing all elements for which the given function returns a true value.

func (*Queue[T]) Find

func (q *Queue[T]) Find(f func(index int, value T) bool) (index int, value T)

Find returns the first element of the container for which the given function returns a true value.

func (*Queue[T]) FromJSON

func (q *Queue[T]) FromJSON(data []byte) error

FromJSON populates list's elements from the input JSON representation.

func (*Queue[T]) Full

func (q *Queue[T]) Full() bool

Full returns true if the queue is full.

func (*Queue[T]) Iterator

func (q *Queue[T]) Iterator() *Iterator[T]

Iterator returns a stateful iterator whose elements are key/value pairs.

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() (_ T, _ bool)

Peek returns the first value in the queue without removing it.

func (*Queue[T]) Size

func (q *Queue[T]) Size() int

Size returns the size of the queue.

func (*Queue[T]) String

func (q *Queue[T]) String() string

String returns a string representation of the queue.

func (*Queue[T]) ToJSON

func (q *Queue[T]) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of list's elements.

func (*Queue[T]) Values

func (q *Queue[T]) Values() []T

Values returns all values in the queue.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL