diff --git a/leveldb/db.go b/leveldb/db.go index 384c498..24c6ba9 100644 --- a/leveldb/db.go +++ b/leveldb/db.go @@ -141,12 +141,12 @@ func (db *DB) NewWriteBatch() *WriteBatch { return wb } -//limit <= 0, unlimit +//limit < 0, unlimit func (db *DB) Iterator(min []byte, max []byte, rangeType uint8, limit int) *Iterator { return newIterator(db, db.iteratorOpts, NewRange(min, max, rangeType), limit, IteratorForward) } -//limit <= 0, unlimit +//limit < 0, unlimit func (db *DB) RevIterator(min []byte, max []byte, rangeType uint8, limit int) *Iterator { return newIterator(db, db.iteratorOpts, NewRange(min, max, rangeType), limit, IteratorBackward) } diff --git a/leveldb/iterator.go b/leveldb/iterator.go index 01dd0f4..bb076d1 100644 --- a/leveldb/iterator.go +++ b/leveldb/iterator.go @@ -95,7 +95,7 @@ func (it *Iterator) Valid() bool { return false } - if it.limit > 0 && it.step >= it.limit { + if it.limit >= 0 && it.step >= it.limit { return false } diff --git a/leveldb/leveldb_test.go b/leveldb/leveldb_test.go index 62cd074..2fd4e14 100644 --- a/leveldb/leveldb_test.go +++ b/leveldb/leveldb_test.go @@ -146,7 +146,7 @@ func TestIterator(t *testing.T) { return []byte(fmt.Sprintf("key_%d", i)) } - it = db.Iterator(k(1), k(5), RangeClose, 0) + it = db.Iterator(k(1), k(5), RangeClose, -1) if err := checkIterator(it, 1, 2, 3, 4, 5); err != nil { t.Fatal(err) } @@ -156,22 +156,22 @@ func TestIterator(t *testing.T) { t.Fatal(err) } - it = db.Iterator(k(1), k(5), RangeLOpen, 0) + it = db.Iterator(k(1), k(5), RangeLOpen, -1) if err := checkIterator(it, 2, 3, 4, 5); err != nil { t.Fatal(err) } - it = db.Iterator(k(1), k(5), RangeROpen, 0) + it = db.Iterator(k(1), k(5), RangeROpen, -1) if err := checkIterator(it, 1, 2, 3, 4); err != nil { t.Fatal(err) } - it = db.Iterator(k(1), k(5), RangeOpen, 0) + it = db.Iterator(k(1), k(5), RangeOpen, -1) if err := checkIterator(it, 2, 3, 4); err != nil { t.Fatal(err) } - it = db.RevIterator(k(1), k(5), RangeClose, 0) + it = db.RevIterator(k(1), k(5), RangeClose, -1) if err := checkIterator(it, 5, 4, 3, 2, 1); err != nil { t.Fatal(err) } @@ -181,17 +181,17 @@ func TestIterator(t *testing.T) { t.Fatal(err) } - it = db.RevIterator(k(1), k(5), RangeLOpen, 0) + it = db.RevIterator(k(1), k(5), RangeLOpen, -1) if err := checkIterator(it, 5, 4, 3, 2); err != nil { t.Fatal(err) } - it = db.RevIterator(k(1), k(5), RangeROpen, 0) + it = db.RevIterator(k(1), k(5), RangeROpen, -1) if err := checkIterator(it, 4, 3, 2, 1); err != nil { t.Fatal(err) } - it = db.RevIterator(k(1), k(5), RangeOpen, 0) + it = db.RevIterator(k(1), k(5), RangeOpen, -1) if err := checkIterator(it, 4, 3, 2); err != nil { t.Fatal(err) }