File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
pkg/scheduler/backend/heap Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,9 @@ func (h *data[T]) Len() int { return len(h.queue) }
85
85
// Swap implements swapping of two elements in the heap. This is a part of standard
86
86
// heap interface and should never be called directly.
87
87
func (h * data [T ]) Swap (i , j int ) {
88
+ if i < 0 || j < 0 {
89
+ return
90
+ }
88
91
h .queue [i ], h .queue [j ] = h .queue [j ], h .queue [i ]
89
92
item := h.items [h.queue [i ]]
90
93
item .index = i
@@ -102,6 +105,9 @@ func (h *data[T]) Push(kv interface{}) {
102
105
103
106
// Pop is supposed to be called by container/heap.Pop only.
104
107
func (h * data [T ]) Pop () interface {} {
108
+ if len (h .queue ) == 0 {
109
+ return nil
110
+ }
105
111
key := h .queue [len (h .queue )- 1 ]
106
112
h .queue = h .queue [0 : len (h .queue )- 1 ]
107
113
item , ok := h .items [key ]
Original file line number Diff line number Diff line change @@ -94,6 +94,11 @@ func TestHeapBasic(t *testing.T) {
94
94
}
95
95
prevNum = num
96
96
}
97
+
98
+ _ , err := h .Pop ()
99
+ if err == nil {
100
+ t .Errorf ("expected Pop() to error on empty heap" )
101
+ }
97
102
}
98
103
99
104
// TestHeap_AddOrUpdate_Add tests add capabilities of Heap.AddOrUpdate
You can’t perform that action at this time.
0 commit comments