Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 544 Bytes

README.md

File metadata and controls

26 lines (18 loc) · 544 Bytes

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}