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) {