diff --git a/avlkey/avlkey.go b/avlkey/avlkey.go index b0f7d16..418e223 100644 --- a/avlkey/avlkey.go +++ b/avlkey/avlkey.go @@ -1,8 +1,6 @@ package avl import ( - "log" - "github.com/davecgh/go-spew/spew" "github.com/emirpasic/gods/utils" @@ -246,9 +244,6 @@ func (avl *AVL) Put(key, value interface{}) { parent = cur c := avl.comparator(node.key, cur.key) - if node.key.(int) == 34293 { - log.Println(c, node.key, cur.key) - } if c > -1 { // right child = 1 cur = cur.children[child] @@ -324,6 +319,7 @@ func (avl *AVL) lrrotate(cur *Node) { if mov.children[l] != nil { movparent.children[r] = mov.children[l] + movparent.children[r].parent = movparent movparent.children[r].child = 1 } else { movparent.children[r] = nil @@ -364,6 +360,7 @@ func (avl *AVL) rlrotate(cur *Node) { if mov.children[l] != nil { movparent.children[r] = mov.children[l] + movparent.children[r].parent = movparent movparent.children[r].child = 1 } else { movparent.children[r] = nil @@ -426,6 +423,7 @@ func (avl *AVL) rrotate(cur *Node) { mov.height = getMaxChildrenHeight(mov) + 1 cur.height = getMaxChildrenHeight(cur) + 1 + } func (avl *AVL) lrotate(cur *Node) { diff --git a/avlkey/avlkey_test.go b/avlkey/avlkey_test.go index 8734277..04e0081 100644 --- a/avlkey/avlkey_test.go +++ b/avlkey/avlkey_test.go @@ -254,8 +254,8 @@ func TestPutComparatorRandom(t *testing.T) { // } // } -// const CompartorSize = 300000 -// const NumberMax = 60000000 +const CompartorSize = 300000 +const NumberMax = 60000000 // func BenchmarkIterator(b *testing.B) { // avl := New(utils.IntComparator) @@ -452,41 +452,25 @@ func TestPutComparatorRandom(t *testing.T) { // // } // } -// func BenchmarkPut(b *testing.B) { -// avl := New(utils.IntComparator) +func BenchmarkPut(b *testing.B) { + avl := New(utils.IntComparator) -// for i := 0; i < 100000; i++ { -// avl.Put(randomdata.Number(0, NumberMax)) -// } + for i := 0; i < 100000; i++ { + avl.Put(randomdata.Number(0, NumberMax), i) + } -// b.ResetTimer() -// b.StartTimer() -// b.N = CompartorSize -// for i := 0; i < b.N; i++ { -// avl.Put(randomdata.Number(0, NumberMax)) -// } + b.ResetTimer() + b.StartTimer() -// } + b.N = CompartorSize + for i := 0; i < b.N; i++ { + avl.Put(randomdata.Number(0, NumberMax), i) + } + +} // func BenchmarkGodsRBPut(b *testing.B) { -// rb := redblacktree.NewWithIntComparator() - -// for i := 0; i < 100000; i++ { -// rb.Put(randomdata.Number(0, NumberMax), i) -// } - -// b.ResetTimer() -// b.StartTimer() - -// b.N = CompartorSize -// for i := 0; i < b.N; i++ { -// rb.Put(randomdata.Number(0, NumberMax), i) -// } - -// } - -// func BenchmarkGodsPut(b *testing.B) { -// avl := avltree.NewWithIntComparator() +// avl := redblacktree.NewWithIntComparator() // for i := 0; i < 100000; i++ { // avl.Put(randomdata.Number(0, NumberMax), i) @@ -499,4 +483,21 @@ func TestPutComparatorRandom(t *testing.T) { // for i := 0; i < b.N; i++ { // avl.Put(randomdata.Number(0, NumberMax), i) // } + // } + +func BenchmarkGodsPut(b *testing.B) { + avl := avltree.NewWithIntComparator() + + for i := 0; i < 100000; i++ { + avl.Put(randomdata.Number(0, NumberMax), i) + } + + b.ResetTimer() + b.StartTimer() + + b.N = CompartorSize + for i := 0; i < b.N; i++ { + avl.Put(randomdata.Number(0, NumberMax), i) + } +}