summaryrefslogtreecommitdiff
path: root/pkg/priority_queue/pq.go
blob: 1b33cb927b2e15d6a3568692ab9cc965b94f3737 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package priorityqueue

import "sync"

type PQ struct {
	sync.RWMutex
	bh *BinHeap
}

func NewPriorityQueue() *PQ {
	return &PQ{
		bh: NewBinHeap(),
	}
}

func (p *PQ) Insert(item PQItem) {
	p.Lock()
	p.bh.Insert(item)
	p.Unlock()
}

func (p *PQ) Get() PQItem {
	p.Lock()
	defer p.Unlock()
	return p.bh.GetMax()
}