queue

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package queue is a super simple FIFO concurrent safe queue implementation in Go.

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 channel based concurrent safe queue.

func New

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

New returns an empty concurrent safe queue. Panics if size is 0 or less.

func (*Queue[T]) Cap

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

Cap returns the capacity of the queue.

func (*Queue[T]) Dequeue

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

Dequeue removes and returns the value at the head of the queue. It returns zero value of T if the queue is empty.

func (*Queue[T]) Enqueue

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

Enqueue puts the given value v at the tail of the queue. If the queue is full, the operation is a no-op.

func (*Queue[T]) HasNext

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

HasNext checks if there is a value in the queue. If there is, it returns true and the value can be accessed by Dequeue().

func (*Queue[T]) Len

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

Len Returns the current length of queue.

Jump to

Keyboard shortcuts

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