queue

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 2 Imported by: 1

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 NewQueue

func NewQueue[T any]() Queue[T]

func NewSafeQueue

func NewSafeQueue[T any]() Queue[T]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL