linkedqueue

package
v0.10.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[E any] func(*Queue[E]) error

func WithSafe

func WithSafe[E any]() Option[E]

WithSafe creates a Option that make the linkedlist-backed queue safe for concurrent use.

type Queue

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

Queue represents a queue based on an linkedlist-backed list. This queue implements the FIFO (first-in, first-out) behavior.

func New

func New[E any](cmp func(E, E) int, ops ...Option[E]) (*Queue[E], error)

New creates and initializes a empty queue. The "cmp" function is used to compare elements for equality. Options can be provided to customize the queue's properties (e.g., thread safety).

func NewFromMapKeys

func NewFromMapKeys[K comparable, V any](cmp func(K, K) int, m map[K]V, ops ...Option[K]) (*Queue[K], error)

NewFromMapKeys creates and initializes a queue from the provided map keys. The "cmp" function is used to compare elements for equality. Options can be provided to customize the queue's properties (e.g., thread safety).

func NewFromMapValues

func NewFromMapValues[K comparable, V any](cmp func(V, V) int, m map[K]V, ops ...Option[V]) (*Queue[V], error)

NewFromMapValues creates and initializes a queue from the provided map values. The "cmp" function is used to compare elements for equality. Options can be provided to customize the queue's properties (e.g., thread safety).

func NewFromSlice

func NewFromSlice[E any](cmp func(E, E) int, slice []E, ops ...Option[E]) (*Queue[E], error)

NewFromSlice creates and initializes a queue from the provided slice. The "cmp" function is used to compare elements for equality. Options can be provided to customize the queue's properties (e.g., thread safety).

func (*Queue[E]) Clear

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

Clear removes all elements from the queue.

func (*Queue[E]) Clone

func (q *Queue[E]) Clone() *Queue[E]

Clone returns a deep copy of the queue.

func (*Queue[E]) Dequeue

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

Dequeue removes first element of the queue. Returns zero value of element and false if queue is empty.

func (*Queue[E]) Enqueue

func (q *Queue[E]) Enqueue(e E)

Enqueue adds a element to the end of the queue.

func (*Queue[E]) IsEmpty

func (q *Queue[E]) IsEmpty() bool

IsEmpty reports whether the queue has no element.

func (*Queue[E]) Len

func (q *Queue[E]) Len() int

Len returns the number of elements currently in the queue.

func (*Queue[E]) MarshalJSON

func (q *Queue[E]) MarshalJSON() ([]byte, error)

MarshalJSON will marshal the queue into a JSON-based representation.

func (*Queue[E]) Peek

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

Peek returns first element of the queue without remove it. Returns zero value of element and false if queue is empty.

func (*Queue[E]) String

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

String returns a string representation of the queue.

func (*Queue[E]) UnmarshalJSON

func (q *Queue[E]) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal a JSON-based representation byte slice into the queue.

func (*Queue[E]) Values

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

Values returns all elements in the queue in FIFO(first-in, first-out) order.

Jump to

Keyboard shortcuts

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