iterator first offset bug fix

This commit is contained in:
siddontang 2014-05-08 09:22:51 +08:00
parent af4507fc51
commit 0792eb6e26
2 changed files with 8 additions and 4 deletions

View File

@ -98,8 +98,12 @@ func newIterator(db *DB, opts *levigo.ReadOptions, r *Range, offset int, limit i
} }
for i := 0; i < offset; i++ { for i := 0; i < offset; i++ {
if it.Valid() { if it.it.Valid() {
it.Next() if it.direction == IteratorForward {
it.it.Next()
} else {
it.it.Prev()
}
} }
} }

View File

@ -152,7 +152,7 @@ func TestIterator(t *testing.T) {
} }
it = db.Iterator(k(1), k(5), RangeClose, 1, 3) it = db.Iterator(k(1), k(5), RangeClose, 1, 3)
if err := checkIterator(it, 2, 3); err != nil { if err := checkIterator(it, 2, 3, 4); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -177,7 +177,7 @@ func TestIterator(t *testing.T) {
} }
it = db.RevIterator(k(1), k(5), RangeClose, 1, 3) it = db.RevIterator(k(1), k(5), RangeClose, 1, 3)
if err := checkIterator(it, 4, 3); err != nil { if err := checkIterator(it, 4, 3, 2); err != nil {
t.Fatal(err) t.Fatal(err)
} }