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