完成大部分的copy

This commit is contained in:
2019-03-24 22:21:25 +08:00
parent ba7263c3f9
commit 51acc649a4
12 changed files with 2173 additions and 1271 deletions

View File

@@ -612,7 +612,7 @@ func BenchmarkPut(b *testing.B) {
b.ResetTimer()
b.StartTimer()
execCount := 10
execCount := 50
b.N = len(l) * execCount
for i := 0; i < execCount; i++ {
tree := New(compare.Int)
@@ -624,118 +624,6 @@ 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))
// }
// tree := New(compare.Int)
// 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)
// }
// 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(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())
// }
// tree.RemoveIndex(4)
// t.Error(tree.Index(4))
// t.Error(tree.Values())
// t.Error(tree.debugString())
// t.Error(len(l), tree.debugString(), "\n", "-----------") // 3 6(4)
}
func BenchmarkIndex(b *testing.B) {
tree := New(compare.Int)
l := loadTestData()
b.N = len(l)
for i := 0; i < b.N; i++ {
tree.Put(l[i], i)
}
b.ResetTimer()
b.StartTimer()
b.N = 1000000
var result [50]interface{}
for n := 0; n < b.N; n++ {
i := 0
tree.Traversal(func(v interface{}) bool {
result[i] = v
i++
if i < 50 {
return true
}
log.Print(i)
return false
})
}
}
func BenchmarkTraversal(b *testing.B) {
tree := New(compare.Int)
l := loadTestData()
b.N = len(l)
for i := 0; i < b.N; i++ {
tree.Put(l[i], i)
}
b.ResetTimer()
b.StartTimer()
execCount := 10
b.N = len(l) * execCount
for n := 0; n < execCount; n++ {
i := 0
var result []interface{}
tree.Traversal(func(v interface{}) bool {
result = append(result, v)
i++
if i >= 50 {
return false
}
return true
})
}
}
func BenchmarkGodsRBPut(b *testing.B) {