package plist import ( "log" "testing" "github.com/emirpasic/gods/utils" "github.com/Pallinder/go-randomdata" "github.com/emirpasic/gods/trees/binaryheap" ) type PriorityQ struct { heap *binaryheap.Heap comparator utils.Comparator topk int next *PriorityQ } func (pq *PriorityQ) Push(v interface{}) { } func TestNPQ(t *testing.T) { h1 := binaryheap.NewWithIntComparator() for i := 0; i < 10; i++ { h1.Push(i) } h1.Values()[0] = 3 log.Println(h1) } func TestPriorityQueue(t *testing.T) { p := NewWithInt() for i := 0; i < 20; i++ { p.Push(randomdata.Number(0, 10000)) t.Log(p.String()) } t.Error(p.String()) } func BenchmarkPriorityQueue(b *testing.B) { p := NewWithInt() // for i := 0; i < 100000; i++ { // p.Push(randomdata.Number(0, 100000)) // // p.Values() // } for i := 0; i < b.N; i++ { p.Push(randomdata.Number(0, 100000)) } } func TestHeap(t *testing.T) { heap := binaryheap.NewWithIntComparator() for i := 0; i < 10; i++ { heap.Push(randomdata.Number(0, 1000)) } t.Error(heap.Peek()) t.Error(heap.Values()) utils.Sort(heap.Values(), utils.IntComparator) } func BenchmarkList_InsertValues123(b *testing.B) { a := func(v1, v2 interface{}) int { if v1.(int) > v2.(int) { return -1 } return 1 } h := binaryheap.NewWith(a) TOPK := 50 for i := 0; i < TOPK*1000; i++ { h.Push(i) } b.StartTimer() for i := 0; i < b.N; i++ { h.Push(i) l := []interface{}{} for n := 0; n < TOPK; n++ { v, _ := h.Pop() l = append(l, v) } for _, v := range l { h.Push(v) } } b.StopTimer() }