Documentation ¶
Overview ¶
Package queue implements a FIFO queue generic over any type.
The queue is not safe for concurrent access across goroutines, the caller is responsible for synchronising concurrent access.
Index ¶
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 generic over any type.
A Queue should be instantiated by the New function and not directly.
func Collect ¶ added in v0.7.0
Collect builds a Queue from an iterator of items, pushing items into the queue in the order of iteration.
func From ¶ added in v0.7.0
From builds a Queue from an existing slice of items, pushing items into the queue in the order of the slice.
The queue will be preallocated the size of len(items).
func (*Queue[T]) Empty ¶ added in v0.6.0
Empty returns whether or not the queue is empty.
s := queue.New[string]() s.Empty() // true s.Push("hello") s.Empty() // false
func (*Queue[T]) Items ¶
Items returns the an iterator over the queue in FIFO order.
q := queue.New[string]() q.Push("hello") q.Push("there") qlices.Collect(s.Items()) // [hello there]
func (*Queue[T]) Pop ¶
Pop removes an item from the front of the queue, if the queue is empty, an error will be returned.
q := queue.New[string]() q.Push("hello") q.Push("there") item, _ := q.Pop() fmt.Println(item) // "hello"
func (*Queue[T]) Push ¶
func (q *Queue[T]) Push(item T)
Push adds an item to the back of the queue.
q := queue.New[string]() q.Push("hello")
func (*Queue[T]) Size ¶ added in v0.6.0
Size returns the number of items in the queue.
s := queue.New[string]() s.Size() // 0 s.Push("hello") s.Push("there") s.Size() // 2
func (*Queue[T]) String ¶
String satisfies the fmt.Stringer interface and allows a Queue to be printed.