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 ¶
- type Deque
- func (d *Deque[T]) Back() T
- func (d *Deque[T]) Front() T
- func (d *Deque[T]) Grow(n int)
- func (d *Deque[T]) Item(i int) T
- func (d *Deque[T]) Iterate() iterator.Iterator[T]
- func (d *Deque[T]) Len() int
- func (d *Deque[T]) PopBack() T
- func (d *Deque[T]) PopFront() T
- func (d *Deque[T]) PushBack(item T)
- func (d *Deque[T]) PushFront(item T)
- func (d *Deque[T]) Set(i int, t T)
- func (d *Deque[T]) Shrink(n int)
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 ¶
Grow allocates sufficient space to add n more items without needing to reallocate.
func (*Deque[T]) Item ¶
Item returns the ith item in the deque. 0 is the front and d.Len()-1 is the back.
func (*Deque[T]) Iterate ¶
Iterate iterates over the elements of the deque.
The iterator panics if the deque has been modified since iteration started.
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.