github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xcontainer/priority_queue/queue.go (about)

     1  package priority_queue
     2  
     3  import (
     4  	"container/heap"
     5  )
     6  
     7  type PriorityQueue struct {
     8  	h heap.Interface
     9  }
    10  
    11  func (q *PriorityQueue) Push(x interface{}) {
    12  	heap.Push(q.h, x)
    13  }
    14  
    15  func (q *PriorityQueue) Pop() interface{} {
    16  	return heap.Pop(q.h)
    17  }
    18  
    19  func NewPriorityQueue(h heap.Interface) *PriorityQueue {
    20  	priorityQueue := &PriorityQueue{h: h}
    21  	heap.Init(priorityQueue.h)
    22  	return priorityQueue
    23  }