summaryrefslogtreecommitdiff
path: root/search/search_test.go
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-05 09:53:43 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-05 09:53:43 +0000
commit7f95eddfcab75aea62810f8d122269c0d741e2cf (patch)
tree4f49593b765c527cb4e56017dedce69f06b43562 /search/search_test.go
parent571c58a20097c5cd7ec666ecd24eb75e827a7b3f (diff)
more on redblack bst
Diffstat (limited to 'search/search_test.go')
-rw-r--r--search/search_test.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/search/search_test.go b/search/search_test.go
index 098947d..bf1d1b5 100644
--- a/search/search_test.go
+++ b/search/search_test.go
@@ -1,4 +1,4 @@
-package set
+package search
import (
"fmt"
@@ -27,7 +27,7 @@ func TestBST(t *testing.T) {
}
}
-func test(s Set, l int, t *testing.T) {
+func test(s Put, l int, t *testing.T) {
keys := ds.NewRandomArrayList(l, l)
randoms := ds.NewRandomArrayList(l, -1)
mapping := make(map[int]int, l)
@@ -63,17 +63,17 @@ func test(s Set, l int, t *testing.T) {
testGet := func(key int) int { return get(key, false) }
testDel := func(key int) int { return get(key, true) }
- testSet := func(key, val int) {
- s.Set(key, val)
+ testPut := func(key, val int) {
+ s.Put(key, val)
mapping[key] = val
- //t.Log("Set", key, val)
+ //t.Log("Put", key, val)
testGet(key)
}
- t.Log("Set random key-values", l)
+ t.Log("Put random key-values", l)
var prevKey int
for _, key := range sort.Shuffle(keys) {
- testSet(key, randoms[key])
+ testPut(key, randoms[key])
testGet(prevKey)
prevKey = key
}
@@ -88,9 +88,9 @@ func test(s Set, l int, t *testing.T) {
}
}
-func TestBalancedBST(t *testing.T) {
+func TestRedBlackBST(t *testing.T) {
for i := minLength; i <= maxLength; i *= factor {
- test(NewBalancedBST(), i, t)
+ test(NewRedBlackBST(), i, t)
}
}
@@ -108,20 +108,20 @@ func BenchmarkBST(t *testing.B) {
}
}
-func BenchmarkBalancedBST(t *testing.B) {
- s := NewBalancedBST()
+func BenchmarkRedBlackBST(t *testing.B) {
+ s := NewRedBlackBST()
for i := minLength; i <= maxLength; i *= factor {
benchmark(s, i, t)
}
}
-func benchmark(s Set, l int, b *testing.B) {
+func benchmark(s Put, l int, b *testing.B) {
list := ds.NewRandomArrayList(l, -1)
b.Run(fmt.Sprintf("random(%d)", l), func(b *testing.B) {
b.ResetTimer()
for i, a := range list {
- s.Set(a, i)
+ s.Put(a, i)
}
for _, a := range list {
benchResult, _ = s.Get(a)