Documentation
¶
Index ¶
- type Queue
- func (q *Queue[T]) All() iter.Seq[T]
- func (q *Queue[T]) At(i int) T
- func (q *Queue[T]) Backward() iter.Seq[T]
- func (q *Queue[T]) IsEmpty() bool
- func (q *Queue[T]) Len() int
- func (q *Queue[T]) Peek() (T, bool)
- func (q *Queue[T]) Pop() (T, bool)
- func (q *Queue[T]) Push(x T)
- func (q *Queue[T]) PushMany(xs []T)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a FIFO queue backed by a circular buffer. The zero value for Queue is an empty queue ready to use. Queue is NOT safe for concurrent use.
Example ¶
var q queue.Queue[int] q.Push(3) q.Push(1) q.Push(4) for !q.IsEmpty() { x, ok := q.Pop() if !ok { panic("queue should not be empty here") } fmt.Println(x) }
Output: 3 1 4
func (*Queue[T]) All ¶
All returns an iterator over all elements in the queue. Do not modify the queue while iterating.
Example ¶
var q queue.Queue[int] q.Push(3) q.Push(1) q.Push(4) for x := range q.All() { fmt.Println(x) }
Output: 3 1 4
func (*Queue[T]) At ¶ added in v0.4.0
At returns the element at the specified index. If the index is out of range, it panics.
func (*Queue[T]) Backward ¶ added in v0.3.0
Backward returns an iterator over all elements in the queue in reverse order (newest first). Do not modify the queue while iterating.
func (*Queue[T]) Peek ¶
Peek returns the element at the front of the queue without removing it. If the queue is empty, Peek returns the zero value of T and false.
Click to show internal directories.
Click to hide internal directories.