summaryrefslogtreecommitdiff
path: root/pkg/priority_queue/pq.go
blob: 2ff52a797182272378a8a75dd7cbfd97c8292733 (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
27
28
29
30
package priorityqueue

import (
	"sync"

	priorityqueue "github.com/spiral/roadrunner/v2/common/priority_queue"
)

type PQ struct {
	sync.RWMutex
	bh *BinHeap
}

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

func (p *PQ) GetMax() priorityqueue.Item {
	p.Lock()
	defer p.Unlock()
	return p.bh.GetMax()
}

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