大部分完成
This commit is contained in:
parent
9e2bdb12dd
commit
c8af06bbab
|
@ -1,8 +1,6 @@
|
|||
package pqueue
|
||||
|
||||
import (
|
||||
"474420502.top/eson/structure/compare"
|
||||
)
|
||||
import "474420502.top/eson/structure/compare"
|
||||
|
||||
type PriorityQueue struct {
|
||||
queue *vbTree
|
||||
|
|
|
@ -3,6 +3,8 @@ package pqueue
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"474420502.top/eson/structure/compare"
|
||||
)
|
||||
|
||||
|
@ -77,6 +79,48 @@ func TestQueueGet(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestQueueRemove(t *testing.T) {
|
||||
pq := New(compare.Int)
|
||||
l := []int{32, 10, 53, 78, 90, 1, 4}
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
|
||||
content := ""
|
||||
for _, v := range l {
|
||||
t.Error(pq.Top())
|
||||
pq.Remove(v)
|
||||
content += spew.Sprint(pq.Values())
|
||||
}
|
||||
|
||||
if content != "[1 4 10 53 78 90][1 4 53 78 90][1 4 78 90][1 4 90][1 4][4][]" {
|
||||
t.Error(content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueRemoveIndex(t *testing.T) {
|
||||
pq := New(compare.Int)
|
||||
l := []int{32, 10, 53, 78, 90, 1, 4}
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
|
||||
content := ""
|
||||
for range l {
|
||||
pq.RemoveWithIndex(0)
|
||||
content += spew.Sprint(pq.Values())
|
||||
}
|
||||
|
||||
if content != "[1 4 10 32 53 78][1 4 10 32 53][1 4 10 32][1 4 10][1 4][1][]" {
|
||||
t.Error(content)
|
||||
}
|
||||
|
||||
if pq.RemoveWithIndex(0) {
|
||||
t.Error("pq is not exist elements")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestQueueIndex(t *testing.T) {
|
||||
pq := New(compare.Int)
|
||||
for _, v := range []int{32, 10, 53, 78, 90, 1, 4} {
|
||||
|
@ -152,6 +196,23 @@ ALL:
|
|||
}
|
||||
}
|
||||
|
||||
func BenchmarkQueueRemove(b *testing.B) {
|
||||
l := loadTestData()
|
||||
|
||||
pq := New(compare.Int)
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
|
||||
b.N = len(l)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
for _, v := range l {
|
||||
pq.Remove(v)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkQueueIndex(b *testing.B) {
|
||||
|
||||
l := loadTestData()
|
||||
|
|
|
@ -32,13 +32,13 @@ func Save(t *testing.T) {
|
|||
// l = append(l, v)
|
||||
// }
|
||||
|
||||
//m := make(map[int]int)
|
||||
m := make(map[int]int)
|
||||
for i := 0; len(l) < CompareSize; i++ {
|
||||
v := randomdata.Number(0, NumberMax)
|
||||
// if _, ok := m[v]; !ok {
|
||||
// m[v] = v
|
||||
l = append(l, v)
|
||||
// }
|
||||
if _, ok := m[v]; !ok {
|
||||
m[v] = v
|
||||
l = append(l, v)
|
||||
}
|
||||
}
|
||||
|
||||
var result bytes.Buffer
|
||||
|
@ -573,7 +573,7 @@ func BenchmarkGet(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
execCount := 10
|
||||
execCount := 5
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
|
|
Loading…
Reference in New Issue
Block a user