deque

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package deque provides a double ended queue implemented using a ring buffer.

Index

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. It has efficient (i.e. constant time) pop and push to both ends.

NOTE: It is currently implemented as a circular buffer but this detail should not be relied on.

func NewDeque

func NewDeque[T any]() Deque[T]

NewDeque creates a deque of Ts with a default capacity.

func NewDequeWithCapacity

func NewDequeWithCapacity[T any](capacity int) Deque[T]

NewDequeWithCapacity creates a new deque of Ts with the given initial capacity.

func (*Deque[T]) Clear

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

Clear removes all items from the deque.

func (*Deque[T]) Iter

func (d *Deque[T]) Iter(fn IterFunc[T])

Iter calls fn on each item in the deque, starting from the front.

func (*Deque[T]) Len

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

Len returns the number of items currently in the deque.

func (*Deque[T]) PopBack

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

PopBack pops an item from the back of the deque, returning the default value and false if it is empty.

func (*Deque[T]) PopFront

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

PopBack pops an item from the front of the deque, returning the default value and false if it is empty.

func (*Deque[T]) PushBack

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

PushBack adds v to the end of the deque.

func (*Deque[T]) PushFront

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

PushFront adds v to the start of the deque.

type IterFunc

type IterFunc[T any] func(v T)

IterFunc is a function which will be executed for every element in the deque.

Jump to

Keyboard shortcuts

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