queues

package
v0.0.0-...-cd04abb Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkedListQueue

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

func (*LinkedListQueue[T]) Dequeue

func (q *LinkedListQueue[T]) Dequeue() optionals.Optional[T]

func (*LinkedListQueue[T]) Enqueue

func (q *LinkedListQueue[T]) Enqueue(v T)

func (*LinkedListQueue[T]) ForEach

func (q *LinkedListQueue[T]) ForEach(f func(T))

func (*LinkedListQueue[T]) IsEmpty

func (q *LinkedListQueue[T]) IsEmpty() bool

func (*LinkedListQueue[T]) Peek

func (q *LinkedListQueue[T]) Peek() optionals.Optional[T]

func (*LinkedListQueue[T]) Size

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

type Queue

type Queue[T any] interface {
	// Adds an element to the back of the queue.
	Enqueue(T)

	// Removes and returns an element from the front of the queue.
	// Returns None if the queue is empty.
	Dequeue() optionals.Optional[T]

	// Returns (but does not remove) an element from the front of the
	//  queue. Returns None if the queue is empty.
	Peek() optionals.Optional[T]

	// Returns true if the queue is empty.
	IsEmpty() bool

	// Returns the length of the queue.
	Size() int

	// Calls the given function with each element in the queue, from
	// front to back.
	ForEach(func(T))
}

A FIFO queue.

func NewLinkedListQueue

func NewLinkedListQueue[T any](elements ...T) Queue[T]

func NewQueue

func NewQueue[T any](elements ...T) Queue[T]

Returns a new FIFO queue containing the given elements. Equivalent to creating an empty queue and calling Enqueue with each element in turn.

Jump to

Keyboard shortcuts

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