213
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package avlindex
|
||||
package vbtkey
|
||||
|
||||
import (
|
||||
"474420502.top/eson/structure/lastack"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package avlindex
|
||||
package vbtkey
|
||||
|
||||
import (
|
||||
"474420502.top/eson/structure/compare"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
@@ -26,10 +27,10 @@ func (n *Node) String() string {
|
||||
|
||||
type Tree struct {
|
||||
root *Node
|
||||
comparator comparator.Comparator
|
||||
comparator compare.Compare
|
||||
}
|
||||
|
||||
func New(comparator comparator.Comparator) *Tree {
|
||||
func New(comparator compare.Compare) *Tree {
|
||||
return &Tree{comparator: comparator}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package avlindex
|
||||
package vbtkey
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -8,16 +8,16 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"474420502.top/eson/structure/compare"
|
||||
"github.com/huandu/skiplist"
|
||||
|
||||
"github.com/Pallinder/go-randomdata"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/emirpasic/gods/trees/avltree"
|
||||
"github.com/emirpasic/gods/trees/redblacktree"
|
||||
"github.com/emirpasic/gods/utils"
|
||||
)
|
||||
|
||||
const CompartorSize = 1000000
|
||||
const CompareSize = 1000000
|
||||
const NumberMax = 50000000
|
||||
|
||||
func Save(t *testing.T) {
|
||||
@@ -33,7 +33,7 @@ func Save(t *testing.T) {
|
||||
// }
|
||||
|
||||
//m := make(map[int]int)
|
||||
for i := 0; len(l) < CompartorSize; i++ {
|
||||
for i := 0; len(l) < CompareSize; i++ {
|
||||
v := randomdata.Number(0, NumberMax)
|
||||
// if _, ok := m[v]; !ok {
|
||||
// m[v] = v
|
||||
@@ -61,7 +61,7 @@ func loadTestData() []int {
|
||||
}
|
||||
|
||||
func TestIndexRange(t *testing.T) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
l := []int{7, 14, 14, 14, 16, 17, 20, 30, 21, 40, 50, 3, 40, 40, 40, 15}
|
||||
for _, v := range l {
|
||||
tree.Put(v, v)
|
||||
@@ -122,7 +122,7 @@ func TestIndexRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAround(t *testing.T) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
for _, v := range []int{7, 14, 14, 14, 16, 17, 20, 30, 21, 40, 50, 3, 40, 40, 40, 15} {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func TestGetAround(t *testing.T) {
|
||||
func TestPutComparatorRandom(t *testing.T) {
|
||||
|
||||
for n := 0; n < 300000; n++ {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
godsavl := avltree.NewWithIntComparator()
|
||||
|
||||
content := ""
|
||||
@@ -220,7 +220,7 @@ func TestPutComparatorRandom(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
for _, v := range []int{2383, 7666, 3055, 39016, 57092, 27897, 36513, 1562, 22574, 23202} {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetRange(t *testing.T) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
for _, v := range []int{5, 6, 8, 10, 13, 17, 1, 2, 40, 30} {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func TestGetRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTravalsal(t *testing.T) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
for _, v := range []int{5, 6, 8, 10, 13, 17, 1, 2, 40, 30} {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func TestTravalsal(t *testing.T) {
|
||||
func TestRemoveAll(t *testing.T) {
|
||||
ALL:
|
||||
for c := 0; c < 5000; c++ {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
gods := avltree.NewWithIntComparator()
|
||||
var l []int
|
||||
m := make(map[int]int)
|
||||
@@ -357,7 +357,7 @@ func TestRemove(t *testing.T) {
|
||||
|
||||
ALL:
|
||||
for N := 0; N < 5000; N++ {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
gods := avltree.NewWithIntComparator()
|
||||
|
||||
var l []int
|
||||
@@ -423,7 +423,7 @@ func BenchmarkGetRange(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkIndexRange(b *testing.B) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
|
||||
@@ -460,7 +460,7 @@ func BenchmarkSkipListSet(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkIterator(b *testing.B) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
@@ -486,7 +486,7 @@ func BenchmarkIterator(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkRemove(b *testing.B) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
@@ -541,7 +541,7 @@ func BenchmarkGodsRBRemove(b *testing.B) {
|
||||
|
||||
func BenchmarkGet(b *testing.B) {
|
||||
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
@@ -615,7 +615,7 @@ func BenchmarkPut(b *testing.B) {
|
||||
execCount := 10
|
||||
b.N = len(l) * execCount
|
||||
for i := 0; i < execCount; i++ {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
for _, v := range l {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
@@ -632,7 +632,7 @@ func TestPutStable(t *testing.T) {
|
||||
// l = append(l, randomdata.Number(3, 69))
|
||||
// }
|
||||
|
||||
// tree := New(utils.IntComparator)
|
||||
// tree := New(compare.Int)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v, v)
|
||||
// }
|
||||
@@ -680,7 +680,7 @@ func TestPutStable(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkIndex(b *testing.B) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
@@ -709,7 +709,7 @@ func BenchmarkIndex(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkTraversal(b *testing.B) {
|
||||
tree := New(utils.IntComparator)
|
||||
tree := New(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
|
||||
Reference in New Issue
Block a user