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;
import static org.iq80.leveldb.impl.SequenceNumber.MAX_SEQUENCE_NUMBER;
public class InternalUserComparator implements UserComparator
    public InternalUserComparator(InternalKeyComparator internalKeyComparator)
    {
        this. = internalKeyComparator;
    }
    @Override
    public int compare(Slice leftSlice right)
    {
        return .compare(new InternalKey(left), new InternalKey(right));
    }
    @Override
    public String name() {
        return .name();
    }
    @Override
    public Slice findShortestSeparator(
            Slice start,
            Slice limit)
    {
        // Attempt to shorten the user portion of the key
        Slice startUserKey = new InternalKey(start).getUserKey();
        Slice limitUserKey = new InternalKey(limit).getUserKey();
        Slice shortestSeparator = .getUserComparator().findShortestSeparator(startUserKeylimitUserKey);
        if (.getUserComparator().compare(startUserKeyshortestSeparator) < 0) {
            // User key has become larger.  Tack on the earliest possible
            // number to the shortened user key.
            InternalKey newInternalKey = new InternalKey(shortestSeparator.);
            Preconditions.checkState(compare(startnewInternalKey.encode()) < 0);// todo
            Preconditions.checkState(compare(newInternalKey.encode(), limit) < 0);// todo
            return newInternalKey.encode();
        }
        return start;
    }
    @Override
    public Slice findShortSuccessor(Slice key)
    {
        Slice userKey = new InternalKey(key).getUserKey();
        Slice shortSuccessor = .getUserComparator().findShortSuccessor(userKey);
        if (.getUserComparator().compare(userKeyshortSuccessor) < 0) {
            // User key has become larger.  Tack on the earliest possible
            // number to the shortened user key.
            InternalKey newInternalKey = new InternalKey(shortSuccessor.);
            Preconditions.checkState(compare(keynewInternalKey.encode()) < 0);// todo
            return newInternalKey.encode();
        }
        return key;
    }
New to GrepCode? Check out our FAQ X