deque

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 3 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package deque contains a double-ended queue.

Example
var deque Deque[string]

deque.PushFront("a")
deque.PushFront("b")
fmt.Println(deque.PopFront())
deque.PushBack("c")
deque.PushBack("d")
fmt.Println(deque.PopBack())
fmt.Println(deque.PopFront())
Output:
b
d
a

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deque

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

Deque is a double-ended queue, allowing push and pop to both the front and back of the queue. Pushes and pops are amortized O(1). The zero-value is ready to use. Deque should not be copied after first use.

func (*Deque[T]) Back

func (d *Deque[T]) Back() T

Back returns the item at the back of the deque. It panics if the deque is empty.

func (*Deque[T]) Front

func (d *Deque[T]) Front() T

Front returns the item at the front of the deque. It panics if the deque is empty.

func (*Deque[T]) Grow

func (d *Deque[T]) Grow(n int)

Grow allocates sufficient space to add n more items without needing to reallocate.

func (*Deque[T]) Item

func (d *Deque[T]) Item(i int) T

Item returns the ith item in the deque. 0 is the front and d.Len()-1 is the back.

func (*Deque[T]) Iterate

func (d *Deque[T]) Iterate() iterator.Iterator[T]

Iterate iterates over the elements of the deque.

The iterator panics if the deque has been modified since iteration started.

func (*Deque[T]) Len

func (d *Deque[T]) Len() int

Len returns the number of items in the deque.

func (*Deque[T]) PopBack

func (d *Deque[T]) PopBack() T

PopBack removes and returns the item at the back of the deque. It panics if the deque is empty.

func (*Deque[T]) PopFront

func (d *Deque[T]) PopFront() T

PopFront removes and returns the item at the front of the deque. It panics if the deque is empty.

func (*Deque[T]) PushBack

func (d *Deque[T]) PushBack(item T)

PushFront adds item to the back of the deque.

func (*Deque[T]) PushFront

func (d *Deque[T]) PushFront(item T)

PushFront adds item to the front of the deque.

func (*Deque[T]) Set added in v0.15.1

func (d *Deque[T]) Set(i int, t T)

Set sets the ith item in the deque. 0 is the front and d.Len()-1 is the back.

func (*Deque[T]) Shrink added in v0.10.0

func (d *Deque[T]) Shrink(n int)

Shrink reallocates the backing buffer for d, if necessary, so that it fits only the current size plus at most n extra items.

Jump to

Keyboard shortcuts

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