| 207 | } |
| 208 | |
| 209 | void DBIter::Prev() { |
| 210 | assert(valid_); |
| 211 | |
| 212 | if (direction_ == kForward) { // Switch directions? |
| 213 | // iter_ is pointing at the current entry. Scan backwards until |
| 214 | // the key changes so we can use the normal reverse scanning code. |
| 215 | assert(iter_->Valid()); // Otherwise valid_ would have been false |
| 216 | SaveKey(ExtractUserKey(iter_->key()), &saved_key_); |
| 217 | while (true) { |
| 218 | iter_->Prev(); |
| 219 | if (!iter_->Valid()) { |
| 220 | valid_ = false; |
| 221 | saved_key_.clear(); |
| 222 | ClearSavedValue(); |
| 223 | return; |
| 224 | } |
| 225 | if (user_comparator_->Compare(ExtractUserKey(iter_->key()), saved_key_) < |
| 226 | 0) { |
| 227 | break; |
| 228 | } |
| 229 | } |
| 230 | direction_ = kReverse; |
| 231 | } |
| 232 | |
| 233 | FindPrevUserEntry(); |
| 234 | } |
| 235 | |
| 236 | void DBIter::FindPrevUserEntry() { |
| 237 | assert(direction_ == kReverse); |