changed peek to include an offset
This commit is contained in:
parent
e598bfcfa1
commit
92777666a9
@ -58,16 +58,17 @@ func (q *PriorityQueue[T]) Len() int {
|
|||||||
return len(q.items)
|
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()
|
q.lock.RLock()
|
||||||
defer q.lock.RUnlock()
|
defer q.lock.RUnlock()
|
||||||
|
|
||||||
if len(q.items) == 0 {
|
if offset < 0 || offset >= len(q.items) {
|
||||||
var def T
|
var t T
|
||||||
return def, false
|
return t, false
|
||||||
}
|
}
|
||||||
|
|
||||||
return q.items[0].value, true
|
return q.items[offset].value, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *PriorityQueue[T]) Clear() {
|
func (q *PriorityQueue[T]) Clear() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user