pqueue

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: GPL-3.0 Imports: 8 Imported by: 1

README

pqueue

GoDoc

A collection of concurrency-safe generic priority queue implementations.

[!NOTE] This package is under development, and I plan to add more implementations in the future.

About

Every priority queue (except Circular FIFO, obviously) in this package is a generic struct, where key K has constraint cmp.Ordered and value V has constraint any. All priority queues are min-heap-based (i.e., the smallest key has the highest priority) and allow for duplicate keys/priorities.

Contributing

I am just one guy working on this in my free time for fun. So, if you have any suggestions or issues, please feel free to open an issue or pull request!

Implementations

Currently, this package provides the following queues.

Time Complexities
Type findMin removeMin insert meld
Binary Θ(1) Θ(log n) Θ(log n) Θ(n)
Circular FIFO Θ(1) Θ(1) Θ(1) Θ(1)
Pairing Θ(1) O(log n) am. Θ(1) Θ(1)
Skew Θ(1) O(log n) am. O(log n) am. O(log n) am.
Skew Binomial Θ(1) Θ(log n) Θ(1) Θ(log n)
Benchmarks

Apple MacBook Pro (M4 Pro, 24GB RAM)

Type push meld pop
Binary 49.40 ns/op 17.72 ns/node 502.7 ns/op
Circular FIFO 24.46 ns/op 2.58×10-5 ns/node 5.945 ns/op
Pairing 48.17 ns/op 4.83×10-4 ns/node 728.0 ns/op
Skew 193.6 ns/op 3.103×10-4 ns/node 587.9 ns/op
Skew Binomial 62.05 ns/op 6.102×10-4 ns/node 1070 ns/op

Documentation

Overview

Package pqueue provides concurrency-safe priority queue implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ConcurrencySafetyError = errors.New("concurrency-safety error: one or more queues share the same underlying" +
		"ID. ensure that all queues are being created via their designated constructors")
)

Functions

This section is empty.

Types

type Binary added in v1.1.0

type Binary[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

Binary is a concurrency-safe, min-priority queue built on a binary heap.

func NewBinary added in v1.1.0

func NewBinary[K cmp.Ordered, V any]() *Binary[K, V]

func (*Binary[K, V]) Clear added in v1.1.0

func (b *Binary[K, V]) Clear()

func (*Binary[K, V]) Meld added in v1.1.0

func (b *Binary[K, V]) Meld(other *Binary[K, V])

func (*Binary[K, V]) Peek added in v1.1.0

func (b *Binary[K, V]) Peek() V

func (*Binary[K, V]) Pop added in v1.1.0

func (b *Binary[K, V]) Pop() (v V, ok bool)

func (*Binary[K, V]) Push added in v1.1.0

func (b *Binary[K, V]) Push(v V, priority K)

func (*Binary[K, V]) Size added in v1.1.0

func (b *Binary[K, V]) Size() int

type CircularBuffer added in v1.2.0

type CircularBuffer[T any] struct {
	// contains filtered or unexported fields
}

func NewCircularBuffer added in v1.2.0

func NewCircularBuffer[T any]() *CircularBuffer[T]

func (*CircularBuffer[T]) Clear added in v1.2.2

func (cb *CircularBuffer[T]) Clear()

func (*CircularBuffer[T]) Meld added in v1.2.0

func (cb *CircularBuffer[T]) Meld(other *CircularBuffer[T])

func (*CircularBuffer[T]) Peek added in v1.2.0

func (cb *CircularBuffer[T]) Peek() T

func (*CircularBuffer[T]) Pop added in v1.2.0

func (cb *CircularBuffer[T]) Pop() (v T, ok bool)

func (*CircularBuffer[T]) Push added in v1.2.0

func (cb *CircularBuffer[T]) Push(v T)

func (*CircularBuffer[T]) Size added in v1.2.2

func (cb *CircularBuffer[T]) Size() int

type CrossMeldable added in v1.2.0

type CrossMeldable interface {
	CrossMeld(other CrossMeldable)
}

type Pairing

type Pairing[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

Pairing is a concurrency-safe, min-priority queue built on a pairing heap.

func NewPairing

func NewPairing[K cmp.Ordered, V any]() *Pairing[K, V]

func (*Pairing[K, V]) Clear

func (p *Pairing[K, V]) Clear()

func (*Pairing[K, V]) Meld

func (p *Pairing[K, V]) Meld(other *Pairing[K, V])

Meld merges another Pairing queue into this one and clears it.

func (*Pairing[K, V]) Peek

func (p *Pairing[K, V]) Peek() V

func (*Pairing[K, V]) Pop

func (p *Pairing[K, V]) Pop() (v V, ok bool)

func (*Pairing[K, V]) Push

func (p *Pairing[K, V]) Push(v V, priority K)

func (*Pairing[K, V]) Size

func (p *Pairing[K, V]) Size() int

type Skew

type Skew[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

Skew is a concurrency-safe, min-priority queue built on a skew heap.

func NewSkew

func NewSkew[K cmp.Ordered, V any]() *Skew[K, V]

func (*Skew[K, V]) Clear

func (s *Skew[K, V]) Clear()

func (*Skew[K, V]) Meld

func (s *Skew[K, V]) Meld(other *Skew[K, V])

Meld merges another Skew queue into this one and clears it.

func (*Skew[K, V]) Peek

func (s *Skew[K, V]) Peek() V

func (*Skew[K, V]) Pop

func (s *Skew[K, V]) Pop() (v V, ok bool)

func (*Skew[K, V]) Push

func (s *Skew[K, V]) Push(v V, priority K)

func (*Skew[K, V]) Size

func (s *Skew[K, V]) Size() int

type SkewBinomial added in v1.1.0

type SkewBinomial[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

SkewBinomial is a concurrency-safe, min-priority queue built on a skew binomial heap.

func NewSkewBinomial added in v1.1.0

func NewSkewBinomial[K cmp.Ordered, V any]() *SkewBinomial[K, V]

func (*SkewBinomial[K, V]) Clear added in v1.1.0

func (sb *SkewBinomial[K, V]) Clear()

func (*SkewBinomial[K, V]) Meld added in v1.1.0

func (sb *SkewBinomial[K, V]) Meld(other *SkewBinomial[K, V])

func (*SkewBinomial[K, V]) Peek added in v1.1.0

func (sb *SkewBinomial[K, V]) Peek() V

func (*SkewBinomial[K, V]) Pop added in v1.1.0

func (sb *SkewBinomial[K, V]) Pop() (v V, ok bool)

func (*SkewBinomial[K, V]) Push added in v1.1.0

func (sb *SkewBinomial[K, V]) Push(v V, priority K)

func (*SkewBinomial[K, V]) Size added in v1.1.0

func (sb *SkewBinomial[K, V]) Size() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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