Documentation
¶
Overview ¶
Package deque provides a type-safe, slice-backed, double-ended queue.
Index ¶
- type Deque
- func (d *Deque[T]) Append(ts ...T)deprecated
- func (d *Deque[T]) At(n int) (t T, ok bool)
- func (d *Deque[T]) Back() (t T, ok bool)
- func (d *Deque[T]) Cap() int
- func (d *Deque[T]) Clip()
- func (d *Deque[T]) Front() (v T, ok bool)
- func (d *Deque[T]) Grow(n int)
- func (d *Deque[T]) Head() (t T, ok bool)deprecated
- func (d *Deque[T]) Len() int
- func (d *Deque[T]) PopHead() (t T, ok bool)deprecated
- func (d *Deque[T]) PopTail() (t T, ok bool)deprecated
- func (d *Deque[T]) PushBack(v T)
- func (d *Deque[T]) PushBackSlice(s []T)
- func (d *Deque[T]) PushFront(v T)
- func (d *Deque[T]) PushHead(t T)deprecated
- func (d *Deque[T]) PushTail(t T)deprecated
- func (d *Deque[T]) RemoveBack() (t T, ok bool)
- func (d *Deque[T]) RemoveFront() (t T, ok bool)
- func (d *Deque[T]) Slice() []T
- func (d *Deque[T]) String() string
- func (d *Deque[T]) Swap(i, j int)
- func (d *Deque[T]) Tail() (t T, ok bool)deprecated
- type Sortable
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. It is not concurrency safe.
Example ¶
package main
import (
"fmt"
"sort"
"github.com/carlmjohnson/deque"
)
func main() {
// Make a new deque
d := deque.Of(9, 8, 7, 6)
// Sort it
sort.Sort(deque.Sortable[int]{d})
// Add 5, 4, 3, 2, 1 to the front
for i := 5; i > 0; i-- {
d.PushFront(i)
}
fmt.Println(d)
// Now pop items off the tail
for {
n, ok := d.RemoveBack()
if !ok {
break
}
fmt.Print(n, " ")
}
fmt.Println()
}
Output: Deque{ len: 9, cap: 16, items: [1, 2, 3, 4, 5, 6, 7, 8, 9]} 9 8 7 6 5 4 3 2 1
func (*Deque[T]) Grow ¶
Grow increases the deque's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the deque without another allocation. If n is negative, Grow panics.
func (*Deque[T]) PushBack ¶ added in v0.23.1
func (d *Deque[T]) PushBack(v T)
PushBack adds new value v to the end of the deque.
func (*Deque[T]) PushBackSlice ¶ added in v0.23.1
func (d *Deque[T]) PushBackSlice(s []T)
PushBackSlice adds all items in s to the back of the deque.
func (*Deque[T]) PushFront ¶ added in v0.23.1
func (d *Deque[T]) PushFront(v T)
PushFront adds a new value v to the front of the deque.
func (*Deque[T]) RemoveBack ¶ added in v0.23.1
RemoveBack removes and returns the back of the deque, if any.
func (*Deque[T]) RemoveFront ¶ added in v0.23.1
RemoveFront removes and returns the front of the deque, if any.
func (*Deque[T]) Slice ¶
func (d *Deque[T]) Slice() []T
Slice returns a slice with a copy of the deque.