On heap removal, only cut if not last elem

This commit is contained in:
Sam Boyer 2016-03-23 14:40:59 -04:00
Родитель 969eb26b8c
Коммит ad4e283396
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -97,12 +97,18 @@ func (u *unselected) Pop() (v interface{}) {
return v
}
// remove takes an ProjectIdentifier out of the priority queue (if it was
// remove takes a ProjectIdentifier out of the priority queue (if it was
// present), then reapplies the heap invariants.
func (u *unselected) remove(id ProjectIdentifier) {
for k, pi := range u.sl {
if pi == id {
u.sl = append(u.sl[:k], u.sl[k+1:]...)
if k == len(u.sl)-1 {
// if we're on the last element, just pop, no splice
u.sl = u.sl[:len(u.sl)-1]
} else {
u.sl = append(u.sl[:k], u.sl[k+1:]...)
}
break
// TODO need to heap.Fix()? shouldn't have to...
}
}