Documentation
¶
Overview ¶
Package cyqueue implements a circular queue.
Example ¶
q := New[string](3)
seq := q.Push("foo")
q.Push("bar")
q.Push("baz")
elem, ok := q.Get(seq)
fmt.Println(seq, elem, ok)
q.Push("qux")
elem, ok = q.Get(seq)
fmt.Println(seq, elem, ok)
for seq, elem := range q.All() {
fmt.Println(seq, elem)
}
Output: 1 foo true 1 false 4 qux 3 baz 2 bar
Index ¶
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 circular queue with elements of type T. Methods on Queue are safe for concurrent use.
func (*Queue[T]) All ¶
All iterates over the queue's elements with their sequential numbers, tail to head (newest elements first).
func (*Queue[T]) Copy ¶
Copy returns a shallow copy of the queue, head to tail (oldest elements first), and the first element's sequential number (each subsequent element's being 1 greater than the preceding one).
func (*Queue[T]) Get ¶
Get returns the element with the given sequential number as returned by Queue.Push. If the element with this number has not yet been pushed or has already been discarded, Get returns zero, false.