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.util.SizeOf.SIZE_OF_LONG;
 
 public class MemTable implements SeekingIterable<InternalKeySlice>
 {
     private final ConcurrentSkipListMap<InternalKeySlicetable;
     private final AtomicLong approximateMemoryUsage = new AtomicLong();
 
     public MemTable(InternalKeyComparator internalKeyComparator)
     {
          = new ConcurrentSkipListMap<InternalKeySlice>(internalKeyComparator);
     }
 
     public boolean isEmpty()
     {
         return .isEmpty();
     }
 
     public long approximateMemoryUsage()
     {
         return .get();
     }
 
     public void add(long sequenceNumberValueType valueTypeSlice keySlice value)
     {
         Preconditions.checkNotNull(valueType"valueType is null");
         Preconditions.checkNotNull(key"key is null");
         Preconditions.checkNotNull(valueType"valueType is null");
 
         InternalKey internalKey = new InternalKey(keysequenceNumbervalueType);
         .put(internalKeyvalue);
 
         .addAndGet(key.length() +  + value.length());
     }
 
     public LookupResult get(LookupKey key)
     {
         Preconditions.checkNotNull(key"key is null");
 
         InternalKey internalKey = key.getInternalKey();
         Entry<InternalKeySliceentry = .ceilingEntry(internalKey);
         if (entry == null) {
             return null;
         }
 
         InternalKey entryKey = entry.getKey();
         if (entryKey.getUserKey().equals(key.getUserKey())) {
             if (entryKey.getValueType() == .) {
                 return LookupResult.deleted(key);
             } else {
                 return LookupResult.ok(keyentry.getValue());
             }
         }
         return null;
     }
 
     @Override
     public MemTableIterator iterator()
     {
         return new MemTableIterator();
     }
 
     public class MemTableIterator implements InternalIterator
     {
 
         private PeekingIterator<Entry<InternalKeySlice>> iterator;
 
         public MemTableIterator()
         {
              = Iterators.peekingIterator(.entrySet().iterator());
         }
        @Override
        public boolean hasNext()
        {
            return .hasNext();
        }
        @Override
        public void seekToFirst()
        {
             = Iterators.peekingIterator(.entrySet().iterator());
        }
        @Override
        public void seek(InternalKey targetKey)
        {
             = Iterators.peekingIterator(.tailMap(targetKey).entrySet().iterator());
        }
        @Override
        public InternalEntry peek()
        {
            Entry<InternalKeySliceentry = .peek();
            return new InternalEntry(entry.getKey(), entry.getValue());
        }
        @Override
        public InternalEntry next()
        {
            Entry<InternalKeySliceentry = .next();
            return new InternalEntry(entry.getKey(), entry.getValue());
        }
        @Override
        public void remove()
        {
            throw new UnsupportedOperationException();
        }
    }
New to GrepCode? Check out our FAQ X