If we want to get the prev key, MergeIterator will set its direction as Direction::Backward, and rebuild its heap (move all valid iterators to max heap). This will not modify the states of inner iterators, which is wrong.
To fix this, simply performing seek is not enough. The core problem is the syntax of current Seek::Random is only for forward moving, more details in #25 . With a bi-way random seek, we can easily handle the bug with seek.
Currently we simply rebuild the heap when changing the direction of
MergeIterator
, which is not correct.Consider this case:
After seeking for
6
, the inner iterators ofMergeIterator
will be like:If we want to get the
prev
key,MergeIterator
will set its direction asDirection::Backward
, and rebuild its heap (move all valid iterators to max heap). This will not modify the states of inner iterators, which is wrong.Then move to the previous key of the current state:
The output would be
7
.To fix this, simply performing
seek
is not enough. The core problem is the syntax of currentSeek::Random
is only for forward moving, more details in #25 . With a bi-way random seek, we can easily handle the bug withseek
.Ref: #25