GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - dnaeon/go-priorityqueue: Simple and generic implementation of priority queues in Go

BranchesTags
Open more actions menu

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
priority_queue.go
priority_queue.go
 
 
priority_queue_test.go
priority_queue_test.go
 
 
renovate.json
renovate.json
 
 

Repository files navigation

go-priorityqueue

Build Status Go Reference Go Report Card codecov

A simple, generic implementation of Priority Queue, based on container/heap.

This package is built on top of the functionality already provided by container/heap, and also adds various convenience methods for creating new priority queues, predicates for testing whether the queue is empty, synchronization so it can be safely used by multiple goroutines.

Installation

Execute the following command.

go get -v gopkg.in/dnaeon/go-priorityqueue.v1

Usage

package main

import (
	"fmt"

	pq "gopkg.in/dnaeon/go-priorityqueue.v1"
)

func main() {
	// Create a new priority queue
	queue := pq.New[string, int64](pq.MinHeap)

	// Insert items in the queue
	queue.Put("apple", 10)
	queue.Put("banana", 3)
	queue.Put("pear", 20)
	queue.Put("orange", 15)

	// Update priority of an item
	queue.Update("banana", 42)

	for !queue.IsEmpty() {
		item := queue.Get()
		fmt.Printf("%s: %d\n", item.Value, item.Priority)
	}
	// Output:
	// apple: 10
	// orange: 15
	// pear: 20
	// banana: 42
}

Make sure to check the included test cases for additional examples.

Tests

Run the tests.

make test

License

go-priorityqueue is Open Source and licensed under the BSD License.

Credits

Some parts of go-priorityqueue re-use code from the examples in container/heap.

About

Simple and generic implementation of priority queues in Go

Topics

gogolangpriority-queue

Resources

Readme
BSD-2-Clause license
Activity

Stars

34 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.