Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 the original author or authors. See the notice.md file distributed with this work for additional information regarding copyright ownership. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.iq80.leveldb.impl;
 
 
 
 public final class SnapshotSeekingIterator extends AbstractSeekingIterator<SliceSlice>
 {
     private final DbIterator iterator;
     private final SnapshotImpl snapshot;
     private final Comparator<SliceuserComparator;
 
     public SnapshotSeekingIterator(DbIterator iteratorSnapshotImpl snapshotComparator<SliceuserComparator)
     {
         this. = iterator;
         this. = snapshot;
         this. = userComparator;
         this..getVersion().retain();
     }
 
     public void close() {
         this..getVersion().release();
     }
 
     @Override
     protected void seekToFirstInternal()
     {
         .seekToFirst();
         findNextUserEntry(null);
     }
 
     @Override
     protected void seekInternal(Slice targetKey)
     {
         .seek(new InternalKey(targetKey.getLastSequence(), .));
         findNextUserEntry(null);
     }
 
     @Override
     protected Entry<SliceSlicegetNextElement()
     {
         if (!.hasNext()) {
             return null;
         }
 
         Entry<InternalKeySlicenext = .next();
 
         // find the next user entry after the key we are about to return
         findNextUserEntry(next.getKey().getUserKey());
 
         return Maps.immutableEntry(next.getKey().getUserKey(), next.getValue());
     }
 
     private void findNextUserEntry(Slice deletedKey)
     {
         // if there are no more entries, we are done
         if (!.hasNext()) {
             return;
         }
 
         do {
             // Peek the next entry and parse the key
             InternalKey internalKey = .peek().getKey();
 
             // skip entries created after our snapshot
             if (internalKey.getSequenceNumber() > .getLastSequence()) {
                 .next();
                 continue;
             }
 
             // if the next entry is a deletion, skip all subsequent entries for that key
             if (internalKey.getValueType() == .) {
                 deletedKey = internalKey.getUserKey();
             }
             else if (internalKey.getValueType() == .) {
                 // is this value masked by a prior deletion record?
                 if (deletedKey == null || .compare(internalKey.getUserKey(), deletedKey) > 0) {
                     return;
                }
            }
            .next();
        } while (.hasNext());
    }
    @Override
    public String toString()
    {
        final StringBuilder sb = new StringBuilder();
        sb.append("SnapshotSeekingIterator");
        sb.append("{snapshot=").append();
        sb.append(", iterator=").append();
        sb.append('}');
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X