Commit c506dea4 authored by Dirk McCormick's avatar Dirk McCormick

feat: add Peek() method

parent 080776c4
......@@ -7,8 +7,10 @@ import "container/heap"
type PQ interface {
// Push adds the ele
Push(Elem)
// Pop returns the highest priority Elem in PQ.
// Pop removes and returns the highest priority Elem in PQ.
Pop() Elem
// Peek returns the highest priority Elem in PQ (without removing it).
Peek() Elem
// Len returns the number of elements in the PQ.
Len() int
// Update `fixes` the PQ.
......@@ -56,6 +58,13 @@ func (w *wrapper) Pop() Elem {
return heap.Pop(&w.heapinterface).(Elem)
}
func (w *wrapper) Peek() Elem {
if len(w.heapinterface.elems) == 0 {
return nil
}
return w.heapinterface.elems[0].(Elem)
}
func (w *wrapper) Update(index int) {
heap.Fix(&w.heapinterface, index)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment