priorityqueues

module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: MIT

README ΒΆ

PriorityQueues

A collection of generic and modular priority queue implementations in Go.

This repository provides four distinct priority queue strategies, each targeting a specific use case or trade-off between simplicity, flexibility, and key-based access.


πŸ“¦ Packages Overview

Package Key Support Priority Injection Stability Typical Use Case
pqs ❌ ❌ (item is prio) ❌ Simple int/float/string queue
mpqs ❌ βœ… βœ… Manual prio for structs
kpqs βœ… ❌ (prio from item) βœ… Tasks with embedded priority
kmpqs βœ… βœ… βœ… Schedulers, process queues

Each package is self-contained and independently tested.


✨ Why multiple queues?

Different use cases require different queue behavior:

  • Minimal overhead? Use pqs.
  • Custom priority from a field? Use kpqs.
  • Keyed access with externally determined priority? Use kmpqs.
  • Just need control over the comparator? Use mpqs.

πŸ“‚ Structure

priorityqueues/
β”œβ”€β”€ kmpqs/  // keyed + manual prio
β”œβ”€β”€ kpqs/   // keyed + prio from item
β”œβ”€β”€ mpqs/   // manual prio only
β”œβ”€β”€ pqs/    // basic queue

Each directory contains:

  • *.go – package implementation
  • *_test.go – unit tests and examples
  • README.md – (optional) package-specific usage and design notes

βœ… Features

  • Go 1.18+ generic support
  • container/heap under the hood
  • Stable priority resolution with tie-breaking by insertion order
  • Optional key-based lookup (kmpqs, kpqs)
  • Custom comparator functions

πŸ” Getting Started

Install with:

go get github.com/byExist/priorityqueues

Import the package you need:

import "github.com/byExist/priorityqueues/kmpqs"

Then initialize and use:

q := kmpqs.New(
	kmpqs.StableMinFirst[*Process, int],
	func(p *Process) string { return p.PID },
)
kmpqs.Enqueue(q, &Process{PID: "123", Name: "nginx"}, 5)

πŸ§ͺ Testing

Each package includes full test coverage and practical Example functions.

Run all tests with:

go test ./...

πŸ“š See Also


πŸ“„ License

MIT License. See LICENSE for details.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

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