diff options
Diffstat (limited to 'queue/elementarypriority.go')
| -rw-r--r-- | queue/elementarypriority.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/queue/elementarypriority.go b/queue/elementarypriority.go index 391d948..9cb9e54 100644 --- a/queue/elementarypriority.go +++ b/queue/elementarypriority.go @@ -50,6 +50,13 @@ func (q *ElementaryPriority[T]) Clear() { } func (q *ElementaryPriority[T]) max() (ind int, max T) { + // Seed from the first element, not the zero value of T: for a queue holding + // only negative values nothing is greater than 0, so a zero seed would + // wrongly report index 0 / value 0 (an element not even in the queue). + if len(q.a) == 0 { + return 0, 0 + } + ind, max = 0, q.a[0] for i, a := range q.a { if a > max { ind, max = i, a |
