Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/searKing/golang/go/exp/container/queue"
)
func main() {
// Create a new queue and put some numbers in it.
var l1 queue.Queue[int]
l1.PushBack(1)
l1.PushBack(2)
l1.PushBack(3)
l1.PushBack(4)
var l2 queue.Queue[int]
l2.PushBack(5)
l2.PushBack(6)
l2.PushBack(7)
l2.PushBack(8)
l1.PushBackSeq(l2.Values())
var s []int
if cleaned := l2.TrimFrontFunc(func(e int) bool {
if e%2 == 1 {
s = append(s, e)
return true
}
return false
}); cleaned {
fmt.Printf("l2: clean leading: %v\n", s)
}
// Iterate through queue and print its contents.
for i, e := range l1.All() {
fmt.Printf("l1[%d]: %d\n", i, e)
}
var i int
for e := range l2.Values() {
fmt.Printf("l2[%d]: %d\n", i, e)
i++
}
}
Output: l2: clean leading: [5] l1[0]: 1 l1[1]: 2 l1[2]: 3 l1[3]: 4 l1[4]: 5 l1[5]: 6 l1[6]: 7 l1[7]: 8 l2[0]: 6 l2[1]: 7 l2[2]: 8
Index ¶
- type Queue
- func (q *Queue[E]) All() iter.Seq2[int, E]
- func (q *Queue[E]) Do(f func(E))
- func (q *Queue[E]) Front() E
- func (q *Queue[E]) Len() int
- func (q *Queue[E]) Next() bool
- func (q *Queue[E]) PopFront() E
- func (q *Queue[E]) PushBack(w E)
- func (q *Queue[E]) PushBackQueue(other *Queue[E])
- func (q *Queue[E]) PushBackSeq(seq iter.Seq[E])
- func (q *Queue[E]) Range(f func(e E) bool)
- func (q *Queue[E]) ShrinkToFit()
- func (q *Queue[E]) TrimFrontFunc(f func(e E) bool) (cleaned bool)
- func (q *Queue[E]) Values() iter.Seq[E]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue[E any] struct { // contains filtered or unexported fields }
A Queue is a queue of FIFO, not a deque.
func (*Queue[E]) All ¶ added in v1.2.121
All returns an iterator over index-value pairs in the queue in the usual order.
func (*Queue[E]) Do ¶
func (q *Queue[E]) Do(f func(E))
Do calls function f on each element of the queue without removing it, in forward order. The behavior of Do is undefined if f changes *q. Deprecated: Use [Range] or [All] instead.
func (*Queue[E]) Front ¶
func (q *Queue[E]) Front() E
Front returns the item at the front of the queue without removing it.
func (*Queue[E]) Next ¶
Next reports whether there are more iterations to execute. Every call to PopFront, even the first one, must be preceded by a call to Next.
func (*Queue[E]) PopFront ¶
func (q *Queue[E]) PopFront() E
PopFront removes and returns the item at the front of the queue.
func (*Queue[E]) PushBack ¶
func (q *Queue[E]) PushBack(w E)
PushBack adds w to the back of the queue.
func (*Queue[E]) PushBackQueue ¶
PushBackQueue inserts a copy of another queue at the back of queue l. Deprecated: Use [PushBackSeq] instead.
func (*Queue[E]) PushBackSeq ¶ added in v1.2.121
PushBackSeq appends the values from seq to the queue.
func (*Queue[E]) Range ¶ added in v1.2.121
Range calls f sequentially for each value present in the queue[E] in forward order. If f returns false, range stops the iteration.
func (*Queue[E]) ShrinkToFit ¶
func (q *Queue[E]) ShrinkToFit()
ShrinkToFit requests the removal of unused capacity.
func (*Queue[E]) TrimFrontFunc ¶
TrimFrontFunc pops all leading elem that satisfying f(c) from the head of the queue, reporting whether any were popped.