diff options
-rw-r--r-- | pkg/priority_queue/binary_heap.go | 13 | ||||
-rw-r--r-- | pkg/priority_queue/binary_heap_test.go | 38 |
2 files changed, 0 insertions, 51 deletions
diff --git a/pkg/priority_queue/binary_heap.go b/pkg/priority_queue/binary_heap.go index 00c73869..02d413aa 100644 --- a/pkg/priority_queue/binary_heap.go +++ b/pkg/priority_queue/binary_heap.go @@ -10,19 +10,6 @@ func NewBinHeap() *BinHeap { return &BinHeap{} } -func (bh *BinHeap) Init(items []PQItem) { - arraySize := len(items) - 1 - - for i := arraySize/2 - 1; i >= 0; i-- { - bh.fixDown(i, arraySize) - } - - for i := arraySize - 1; i >= 1; i-- { - items[0], items[i] = items[i], items[0] - bh.fixDown(0, i-1) - } -} - func (bh *BinHeap) fixUp() { k := len(*bh) - 1 p := (k - 1) >> 1 // k-1 / 2 diff --git a/pkg/priority_queue/binary_heap_test.go b/pkg/priority_queue/binary_heap_test.go index 1b510be3..afeae62c 100644 --- a/pkg/priority_queue/binary_heap_test.go +++ b/pkg/priority_queue/binary_heap_test.go @@ -1,7 +1,6 @@ package priorityqueue import ( - "sort" "testing" "github.com/stretchr/testify/require" @@ -22,18 +21,6 @@ func TestBinHeap_Init(t *testing.T) { bh := NewBinHeap() - bh.Init(a) - - expected := []PQItem{Test(1), Test(2), Test(2), Test(2), Test(2), Test(4), Test(6), Test(23), Test(33), Test(44), Test(99)} - - require.Equal(t, expected, a) -} - -func TestBinHeap_Init2(t *testing.T) { - a := []PQItem{Test(2), Test(23), Test(33), Test(44), Test(1), Test(2), Test(2), Test(2), Test(4), Test(6), Test(99)} - - bh := NewBinHeap() - for i := 0; i < len(a); i++ { bh.Insert(a[i]) } @@ -49,28 +36,3 @@ func TestBinHeap_Init2(t *testing.T) { require.Equal(t, expected, res) } - -func BenchmarkBinHeap_Init(b *testing.B) { - a := []PQItem{Test(2), Test(23), Test(33), Test(44), Test(1), Test(2), Test(2), Test(2), Test(4), Test(6), Test(99)} - bh := NewBinHeap() - - b.ResetTimer() - b.ReportAllocs() - - for i := 0; i < b.N; i++ { - bh.Init(a) - } -} - -func BenchmarkBinHeap_InitStdSort(b *testing.B) { - a := []PQItem{Test(2), Test(23), Test(33), Test(44), Test(1), Test(2), Test(2), Test(2), Test(4), Test(6), Test(99)} - - b.ResetTimer() - b.ReportAllocs() - - for i := 0; i < b.N; i++ { - sort.Slice(a, func(i, j int) bool { - return a[i].Priority() < a[j].Priority() - }) - } -} |