queue

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue is a generic FIFO queue implementation in Go.

func New

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

New creates a new Queue.

func (*Queue[T]) Dequeue

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

Dequeue removes the value at the front of the queue and returns it. If the queue is empty, it returns the zero value of the type T and a boolean false.

func (*Queue[T]) DequeueFromEnd

func (q *Queue[T]) DequeueFromEnd() (T, bool)

DequeueFromEnd removes the value at the end of the queue and returns it. If the queue is empty, it returns the zero value of the type T and a boolean false.

func (*Queue[T]) Enqueue

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

Enqueue adds a value to the back of the queue.

func (*Queue[T]) InsertAt

func (q *Queue[T]) InsertAt(index int, v T)

InsertAt inserts an element at a specified index in the queue. If the index is out of range, it will append the element at the end.

func (*Queue[T]) Peek

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

Peek returns the value at the front of the queue without removing it. If the queue is empty, it returns the zero value of the type T and a boolean false.

func (*Queue[T]) PeekAt

func (q *Queue[T]) PeekAt(index int) (T, bool)

PeekAt returns the value at the specified index without removing it. Returns the peeked element and true if successful, zero value and false if not.

func (*Queue[T]) PeekEnd

func (q *Queue[T]) PeekEnd() (T, bool)

PeekEnd returns the value at the end of the queue without removing it. If the queue is empty, it returns the zero value of the type T and a boolean false.

func (*Queue[T]) RemoveAt

func (q *Queue[T]) RemoveAt(index int) (T, bool)

RemoveAt removes an element at a specified index in the queue. Returns the removed element and true if successful, zero value and false if not.

func (*Queue[T]) Reset

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

Reset completely empties the queue.

func (*Queue[T]) Size

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

Size returns the number of elements in the queue.

Jump to

Keyboard shortcuts

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