queue

package module
v2.0.0-...-75960ed Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 0 Imported by: 7

Documentation

Overview

Package queue provides a fast, ring-buffer queue based on the version suggested by Dariusz Górecki. Using this instead of other, simpler, queue implementations (slice+append or linked list) provides substantial memory and time benefits, and fewer GC pauses.

The queue implemented here is as fast as it is for an additional reason: it is *not* thread-safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue represents a single instance of the queue data structure.

func New

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

New constructs and returns a new Queue.

func (*Queue[V]) Add

func (q *Queue[V]) Add(elem V)

Add puts an element on the end of the queue.

func (*Queue[V]) Get

func (q *Queue[V]) Get(i int) V

Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.

func (*Queue[V]) Length

func (q *Queue[V]) Length() int

Length returns the number of elements currently stored in the queue.

func (*Queue[V]) Peek

func (q *Queue[V]) Peek() V

Peek returns the element at the head of the queue. This call panics if the queue is empty.

func (*Queue[V]) Remove

func (q *Queue[V]) Remove() V

Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.

Jump to

Keyboard shortcuts

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