Closed GoogleCodeExporter closed 9 years ago
We tried having something like this in the iterator interface and it
complicated the implementation a fair amount. Given that you can accomplish
what you want with a fairly small amount of code at the application level, we
didn't feel it was necessary and opted to keep the iterator interface narrower.
Something like this should do what you are asking:
void SeekBack(leveldb::Iterator* iter,
leveldb::Comparator* comparator,
const leveldb::Slice& target) {
iter->Seek(target);
if (!iter->Valid()) {
iter->SeekToFirst();
} else if (comparator->Compare(iter->key(), target) > 0) {
iter->Prev();
}
}
Original comment by j...@google.com
on 19 Oct 2011 at 7:44
That's fair. Thank you for the quick answer.
Original comment by Paolo.Losi
on 19 Oct 2011 at 7:57
[deleted comment]
Is it something wrong for this function? if iterator is invalid, all the value
are greater than target. so, we need to SeekToLast, right?
void SeekBack(leveldb::Iterator* iter,
leveldb::Comparator* comparator,
const leveldb::Slice& target) {
iter->Seek(target);
if (!iter->Valid()) {
iter->SeekToLast();
} else if (comparator->Compare(iter->key(), target) > 0) {
iter->Prev();
}
}
Original comment by liudaok...@gmail.com
on 23 Dec 2011 at 7:40
You are right. If iter is not Valid, the next step should be to call
SeekToLast(), not SeekToFirst().
Original comment by san...@google.com
on 16 Oct 2012 at 11:34
Original issue reported on code.google.com by
Paolo.Losi
on 19 Oct 2011 at 9:39