As an example, I have add several keys to DB just like ,
<1 + 2>
<1 + 3>
<2 + 1>
<2 + 4>
<3 + 2>
First, Seek()
to <1, 2> and then Next()
to <1, 3>
After that, I want to skip the key <2, 1> and <2, 4> (whose prefix are all 2
) and move the iterator to <3, 2> without a new seek
operation.
The use of a new Seek()
operation is unexpected due to that Seek()
is expensive.
Which method should I use?
This skip scan approach is similar to this
I prefer to program like the following lines:
DBIter* it = NewDBIterator(...);
set = {key1, key2, key3, ...};
Iterator key_iter = set.begin();
for (it->SeekToFirst(); it->Valid() && key_iter != set.end(); it->SkipToNext(*key_iter), ++ key_iter) {
// do something
}