From 3d1be547ca2f3c9c57e230e422a6ae9f25759e1b Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 3 Apr 2019 18:24:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=87=E6=80=AA=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avl/avl.go | 8 ++++++-- lastack/lastack_test.go | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/avl/avl.go b/avl/avl.go index 0455b4c..eed5d80 100644 --- a/avl/avl.go +++ b/avl/avl.go @@ -153,7 +153,9 @@ func (tree *Tree) GetRange(k1, k2 interface{}) (result []interface{}) { result = make([]interface{}, 0, 16) - iter := NewIterator(min) + // iter := NewIterator(min) + tree.iter.SetNode(min) + iter := tree.iter for iter.Next() { result = append(result, iter.Value()) if iter.cur == max { @@ -228,7 +230,9 @@ func (tree *Tree) getArountNode(key interface{}) (result [3]*Node) { n = n.children[1] lastc = c case 0: - iter := NewIterator(n) + // iter := NewIterator(n) + tree.iter.SetNode(n) + iter := tree.iter iter.Prev() for iter.Prev() { if tree.Compare(iter.cur.value, n.value) == 0 { diff --git a/lastack/lastack_test.go b/lastack/lastack_test.go index 1281f1d..992ad81 100644 --- a/lastack/lastack_test.go +++ b/lastack/lastack_test.go @@ -25,16 +25,19 @@ func TestPush(t *testing.T) { t.Error(s.String(), " size ", s.size) } + var l []int + for i := 0; i < 10; i++ { v := randomdata.Number(0, 10) s.Push(v) + l = append(l, v) } for i := -1; i < 11; i++ { v, ok := s.Get(i) t.Error(v, ok) } - + t.Error(l) } func BenchmarkGet(b *testing.B) {