queue

package
v2.18.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package queue implements a generic queue using a ring buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Len returns the number of elements available.
	Len() int
	// Clear removes the element at i.
	Clear(i int)
}

A type implementing Interface can be used to store elements in a Queue.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

A Queue wraps an Interface to provide queue operations.

func New

func New(q Interface, n int) *Queue

New creates a new queue that starts with n elements. The interface's length must not change over the course of the queue's usage.

func (*Queue) Front

func (q *Queue) Front() int

Front returns the index of the front of the queue, or -1 if the queue is empty.

func (*Queue) Init

func (q *Queue) Init(r Interface, n int)

Init initializes a queue. The old queue is untouched.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the length of the queue. This is different from the underlying interface's length, which is the queue's capacity.

func (*Queue) Pop

func (q *Queue) Pop() bool

Pop pops an element from the queue, returning whether it succeeded.

func (*Queue) Push

func (q *Queue) Push() int

Push reserves space for an element on the queue, returning its index. If the queue is full, Push returns -1.

Jump to

Keyboard shortcuts

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