changed peek to include an offset

This commit is contained in:
Steve Dudenhoeffer 2022-09-23 22:03:13 -04:00
parent e598bfcfa1
commit 92777666a9

View File

@ -58,16 +58,17 @@ func (q *PriorityQueue[T]) Len() int {
return len(q.items)
}
func (q *PriorityQueue[T]) Peek() (T, bool) {
// offset should be between 0 and Len() - 1
func (q *PriorityQueue[T]) Peek(offset int) (T, bool) {
q.lock.RLock()
defer q.lock.RUnlock()
if len(q.items) == 0 {
var def T
return def, false
if offset < 0 || offset >= len(q.items) {
var t T
return t, false
}
return q.items[0].value, true
return q.items[offset].value, true
}
func (q *PriorityQueue[T]) Clear() {