queue

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 returns length of Queue
	Len() int
	// Push pushes element to end of Queue
	Push(v T)
	// Pop pops element from head of Queue
	Pop() (T, bool)
	// Head returns head element of Queue
	Head() (T, bool)
	// Tail returns tail element of Queue
	Tail() (T, bool)
	// Range calls f sequentially for each element present in the Queue.
	// If f returns false, range stops the iteration.
	Range(f func(T) bool)
	// Clear releases all the entries, resulting in an empty Queue.
	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)

		v, _ := q.Pop()
		fmt.Println(v)

		for v = range q.Range {
			fmt.Println(v)
			continue
		}

		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