kk-min / go-pq

Generic priority queue implementation for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Priority Queue

Generic priority queue implementation for Go.

Usage

type CustomItem struct{
	Key string
	Val int
}

// Create a PriorityQueue of type CustomItem by passing in a "less" comparator function to CreatePQ:
q := pq.CreatePQ[CustomItem](func(a, b CustomItem) bool { return a.Val < b.Val })

// Put items in the Priority Queue:
q.Put(CustomItem{"a", 5})
q.Put(CustomItem{"b", 1})

// Peek the head of the queue:
q.Peek() // CustomItem{"b", 1}

// Get (Dequeue) the head of the queue:
q.Get() // CustomItem{"b", 1}

About

Generic priority queue implementation for Go.

License:MIT License


Languages

Language:Go 100.0%