实现sbt

This commit is contained in:
huangsimin 2019-03-22 19:04:11 +08:00
parent bf96ae47cd
commit c9c830b248
2 changed files with 40 additions and 43 deletions

View File

@ -1,8 +1,6 @@
package avlindex
import (
"log"
"github.com/davecgh/go-spew/spew"
"github.com/emirpasic/gods/utils"
@ -602,7 +600,6 @@ func (tree *Tree) Traversal(every func(v interface{}) bool, traversalMethod ...i
return true
}
if !traverasl(cur.children[0]) {
log.Println(cur)
return false
}
if !every(cur.value) {

View File

@ -552,7 +552,7 @@ func BenchmarkGet(b *testing.B) {
b.ResetTimer()
b.StartTimer()
execCount := 50
execCount := 10
b.N = len(l) * execCount
for i := 0; i < execCount; i++ {
@ -574,7 +574,7 @@ func BenchmarkGodsRBGet(b *testing.B) {
b.ResetTimer()
b.StartTimer()
execCount := 50
execCount := 10
b.N = len(l) * execCount
for i := 0; i < execCount; i++ {
@ -596,7 +596,7 @@ func BenchmarkGodsAvlGet(b *testing.B) {
b.ResetTimer()
b.StartTimer()
execCount := 50
execCount := 10
b.N = len(l) * execCount
for i := 0; i < execCount; i++ {
@ -612,7 +612,7 @@ func BenchmarkPut(b *testing.B) {
b.ResetTimer()
b.StartTimer()
execCount := 1
execCount := 10
b.N = len(l) * execCount
for i := 0; i < execCount; i++ {
tree := New(utils.IntComparator)
@ -625,47 +625,47 @@ func BenchmarkPut(b *testing.B) {
func TestPutStable(t *testing.T) {
// l := []int{14, 18, 20, 21, 22, 23, 19}
for n := 0; n < 1000000; n++ {
var l []int
l = append(l, 60, 5, 15)
for i := 0; len(l) < 11; i++ {
l = append(l, randomdata.Number(3, 69))
}
// for n := 0; n < 1000000; n++ {
// var l []int
// l = append(l, 60, 5, 15)
// for i := 0; len(l) < 11; i++ {
// l = append(l, randomdata.Number(3, 69))
// }
tree := New(utils.IntComparator)
for _, v := range l {
tree.Put(v, v)
}
result := tree.getArountNode(60)
// tree := New(utils.IntComparator)
// for _, v := range l {
// tree.Put(v, v)
// }
// result := tree.getArountNode(60)
if result[2] == nil && tree.indexNode(-1) != result[1] {
t.Error(tree.debugString())
t.Error(tree.Values())
t.Error(result)
}
// if result[2] == nil && tree.indexNode(-1) != result[1] {
// t.Error(tree.debugString())
// t.Error(tree.Values())
// t.Error(result)
// }
result = tree.getArountNode(5)
if result[0] == nil && tree.indexNode(0) != result[1] {
t.Error(tree.debugString())
t.Error(tree.Values())
t.Error(result)
}
// result = tree.getArountNode(5)
// if result[0] == nil && tree.indexNode(0) != result[1] {
// t.Error(tree.debugString())
// t.Error(tree.Values())
// t.Error(result)
// }
result = tree.getArountNode(2)
if result[2] == nil && tree.indexNode(0) != result[2] {
t.Error(tree.debugString())
t.Error(tree.Values())
t.Error(result)
}
// result = tree.getArountNode(2)
// if result[2] == nil && tree.indexNode(0) != result[2] {
// t.Error(tree.debugString())
// t.Error(tree.Values())
// t.Error(result)
// }
result = tree.getArountNode(70)
if result[0] == nil && tree.indexNode(-1) != result[0] {
t.Error(tree.debugString())
t.Error(tree.Values())
t.Error(result)
}
// result = tree.getArountNode(70)
// if result[0] == nil && tree.indexNode(-1) != result[0] {
// t.Error(tree.debugString())
// t.Error(tree.Values())
// t.Error(result)
// }
}
// }
// for _, v := range []int{10, 0, 9, 5, -11, -10, -1, -5} {
// t.Error(tree.Index(v))
// // t.Error(tree.debugString())
@ -720,7 +720,7 @@ func BenchmarkTraversal(b *testing.B) {
b.ResetTimer()
b.StartTimer()
execCount := 50
execCount := 10
b.N = len(l) * execCount
for n := 0; n < execCount; n++ {