Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue[T any] interface { Len() int Push(v T) Pop() (T, bool) Head() (T, bool) Tail() (T, bool) Clear() }
Example ¶
package main
import (
"fmt"
"github.com/xoctopus/x/container/queue"
)
func main() {
for _, q := range []queue.Queue[any]{
queue.NewSafeQueue[any](),
queue.NewQueue[any](),
} {
q.Push(1)
q.Push(2)
q.Push(3)
q.Push(4)
head, _ := q.Head()
tail, _ := q.Tail()
fmt.Println("head:", head)
fmt.Println("tail:", tail)
for {
if v, ok := q.Pop(); ok {
fmt.Println(v)
continue
}
break
}
q.Clear()
q.Len()
_, ok := q.Head()
fmt.Println("head:", ok)
_, ok = q.Tail()
fmt.Println("tail:", ok)
_, ok = q.Pop()
fmt.Println("pop: ", ok)
}
}
Output: head: 1 tail: 4 1 2 3 4 head: false tail: false pop: false head: 1 tail: 4 1 2 3 4 head: false tail: false pop: false
func NewSafeQueue ¶
Click to show internal directories.
Click to hide internal directories.