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)
|
||||
}
|
||||
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user