queue

package
v1.9.7 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IterationCallback added in v1.8.9

type IterationCallback[T any] func(item T, index int) (keepGoing bool)

type IterationDirection added in v1.8.9

type IterationDirection bool

IterationDirection specifies the direction in which to iterate over the items

const (
	Forward  IterationDirection = true
	Backward IterationDirection = false
)

type Q

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

Q is a generic stack/queue structure that supports both stack and queue operations. Stack operations (Push/Pop) are O(1) Queue operations (Enqueue/Dequeue) are O(1) amortized for Enqueue, O(n) for Dequeue

func New

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

New creates a new Q

func (*Q[T]) At

func (q *Q[T]) At(index int) (T, bool)

At returns the item at a specific index

func (*Q[T]) Clear

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

Clear removes all items

func (*Q[T]) Dequeue

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

Dequeue removes and returns the first item from the queue (queue behavior)

func (*Q[T]) Enqueue

func (q *Q[T]) Enqueue(item T)

Enqueue adds an item to the end of the queue (queue behavior)

func (*Q[T]) ForEach added in v1.8.9

func (q *Q[T]) ForEach(callback IterationCallback[T])

ForEach allows you to iterate over the items (from front to back)

func (*Q[T]) ForEachReverse added in v1.8.9

func (q *Q[T]) ForEachReverse(callback IterationCallback[T])

ForEachReverse allows you to iterate over the items (from back to front)

func (*Q[T]) Len

func (q *Q[T]) Len() int

Len returns the number of items in the Q

func (*Q[T]) Peek

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

Peek returns the top item from the stack without removing it

func (*Q[T]) Pop

func (q *Q[T]) Pop() (T, bool)

Pop removes and returns the top item from the stack (stack behavior)

func (*Q[T]) Push

func (q *Q[T]) Push(item T)

Push adds an item to the top of the stack (stack behavior)

Jump to

Keyboard shortcuts

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