leveldb limit < 0 for unlimit

This commit is contained in:
siddontang 2014-05-07 16:44:08 +08:00
parent c9cefc35fa
commit 24d6fb3572
3 changed files with 11 additions and 11 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}