| 53 | } |
| 54 | |
| 55 | void Next() override { |
| 56 | assert(Valid()); |
| 57 | |
| 58 | // Ensure that all children are positioned after key(). |
| 59 | // If we are moving in the forward direction, it is already |
| 60 | // true for all of the non-current_ children since current_ is |
| 61 | // the smallest child and key() == current_->key(). Otherwise, |
| 62 | // we explicitly position the non-current_ children. |
| 63 | if (direction_ != kForward) { |
| 64 | for (int i = 0; i < n_; i++) { |
| 65 | IteratorWrapper* child = &children_[i]; |
| 66 | if (child != current_) { |
| 67 | child->Seek(key()); |
| 68 | if (child->Valid() && |
| 69 | comparator_->Compare(key(), child->key()) == 0) { |
| 70 | child->Next(); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | direction_ = kForward; |
| 75 | } |
| 76 | |
| 77 | current_->Next(); |
| 78 | FindSmallest(); |
| 79 | } |
| 80 | |
| 81 | void Prev() override { |
| 82 | assert(Valid()); |