Documentation
¶
Overview ¶
Package deque implements a double-ended queue (deque) implemented with a growable ring buffer.
This queue has O(1) amortized inserts and removals from both ends of the container. It also has O(1) indexing like a vector.
The core implementation is "ported" (stolen) from Rust's VecDeque.
Index ¶
- type Deque
- func (q *Deque[T]) All() iter.Seq2[int, T]
- func (q *Deque[T]) At(i int) T
- func (q *Deque[T]) Cap() int
- func (q *Deque[T]) Grow(n int)
- func (q *Deque[T]) Len() int
- func (q *Deque[T]) PopAll() iter.Seq[T]
- func (q *Deque[T]) PopBack() (T, bool)
- func (q *Deque[T]) PopFront() (T, bool)
- func (q *Deque[T]) PushBack(values ...T)
- func (q *Deque[T]) PushFront(values ...T)
- func (q *Deque[T]) Reset()
- func (q *Deque[T]) String() string
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. The zero value is ready for use.
func WithCapacity ¶
WithCapacity allocates a deque with the given capacity.
func (*Deque[T]) All ¶
All returns an iterator over the elements in the deque. It does not pop any elements.
func (*Deque[T]) Grow ¶
Grow makes space for at least n more elements to be inserted in the given deque without reallocation.
func (*Deque[T]) PopAll ¶
PopAll empties the deque and returns an iterator over the popped elements. It's not safe to modify the deque while iterating using PopAll.
func (*Deque[T]) PopBack ¶
PopBack removes and returns the last item in the deque if it is non-empty.
func (*Deque[T]) PopFront ¶
PopFront removes and returns the item at index 0 if the deque is non-empty.
func (*Deque[T]) PushBack ¶
func (q *Deque[T]) PushBack(values ...T)
PushBack appends the given items to the back of the deque.
func (*Deque[T]) PushFront ¶
func (q *Deque[T]) PushFront(values ...T)
PushFront prepends the given items to the front of the deque.