Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"github.com/searKing/golang/go/exp/container/queue"
)
func main() {
// Create a new list and put some numbers in it.
l := queue.New[int]()
l.PushBack(1)
l.PushBack(2)
l.PushBack(3)
l.PushBack(4)
l2 := queue.New[int]()
l2.PushBack(5)
l2.PushBack(6)
l2.PushBack(7)
l2.PushBack(8)
l.PushBackQueue(l2)
l2.TrimFrontFunc(func(e int) bool {
return e%2 == 1
})
// Iterate through list and print its contents.
l.Do(func(e int) {
fmt.Println(e)
})
l2.Do(func(e int) {
fmt.Println(e)
})
}
Output: 1 2 3 4 5 6 7 8 6 7 8
Index ¶
- type Queue
- 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]) ShrinkToFit()
- func (q *Queue[E]) TrimFrontFunc(f func(e E) bool) (cleaned bool)
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]) 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.
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. The queues l and other may be the same. They must not be nil.
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.