From 9f2b5018c1197f162ceb5f867c2a555e1662485d Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Fri, 29 Apr 2022 11:37:35 -0700 Subject: [PATCH] sched: remove unused code --- pkg/scheduler/internal/heap/heap.go | 16 ----------- pkg/scheduler/internal/heap/heap_test.go | 36 ------------------------ 2 files changed, 52 deletions(-) diff --git a/pkg/scheduler/internal/heap/heap.go b/pkg/scheduler/internal/heap/heap.go index 49bf9d12388..8bc387aaffc 100644 --- a/pkg/scheduler/internal/heap/heap.go +++ b/pkg/scheduler/internal/heap/heap.go @@ -152,22 +152,6 @@ func (h *Heap) Add(obj interface{}) error { return nil } -// AddIfNotPresent inserts an item, and puts it in the queue. If an item with -// the key is present in the map, no changes is made to the item. -func (h *Heap) AddIfNotPresent(obj interface{}) error { - key, err := h.data.keyFunc(obj) - if err != nil { - return cache.KeyError{Obj: obj, Err: err} - } - if _, exists := h.data.items[key]; !exists { - heap.Push(h.data, &itemKeyValue{key, obj}) - if h.metricRecorder != nil { - h.metricRecorder.Inc() - } - } - return nil -} - // Update is the same as Add in this implementation. When the item does not // exist, it is added. func (h *Heap) Update(obj interface{}) error { diff --git a/pkg/scheduler/internal/heap/heap_test.go b/pkg/scheduler/internal/heap/heap_test.go index 40a8f41da88..f52ba7257b7 100644 --- a/pkg/scheduler/internal/heap/heap_test.go +++ b/pkg/scheduler/internal/heap/heap_test.go @@ -94,42 +94,6 @@ func TestHeap_Add(t *testing.T) { } } -// TestHeap_AddIfNotPresent tests Heap.AddIfNotPresent and ensures that heap -// invariant is preserved after adding items. -func TestHeap_AddIfNotPresent(t *testing.T) { - h := New(testHeapObjectKeyFunc, compareInts) - h.AddIfNotPresent(mkHeapObj("foo", 10)) - h.AddIfNotPresent(mkHeapObj("bar", 1)) - h.AddIfNotPresent(mkHeapObj("baz", 11)) - h.AddIfNotPresent(mkHeapObj("zab", 30)) - h.AddIfNotPresent(mkHeapObj("foo", 13)) // This is not added. - - if len := len(h.data.items); len != 4 { - t.Errorf("unexpected number of items: %d", len) - } - if val := h.data.items["foo"].obj.(testHeapObject).val; val != 10 { - t.Errorf("unexpected value: %d", val) - } - item, err := h.Pop() - if e, a := 1, item.(testHeapObject).val; err != nil || a != e { - t.Fatalf("expected %d, got %d", e, a) - } - item, err = h.Pop() - if e, a := 10, item.(testHeapObject).val; err != nil || a != e { - t.Fatalf("expected %d, got %d", e, a) - } - // bar is already popped. Let's add another one. - h.AddIfNotPresent(mkHeapObj("bar", 14)) - item, err = h.Pop() - if e, a := 11, item.(testHeapObject).val; err != nil || a != e { - t.Fatalf("expected %d, got %d", e, a) - } - item, err = h.Pop() - if e, a := 14, item.(testHeapObject).val; err != nil || a != e { - t.Fatalf("expected %d, got %d", e, a) - } -} - // TestHeap_Delete tests Heap.Delete and ensures that heap invariant is // preserved after deleting items. func TestHeap_Delete(t *testing.T) {