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.table;
 
 
 
 import static org.iq80.leveldb.util.SizeOf.SIZE_OF_INT;

Binary Structure

nameoffsetlengthdescription
entries4varyEntries in order by key
restart indexvary4 * restart countIndex of prefix compression restarts
restart count04Number of prefix compression restarts (used as index into entries)
 
 public class Block implements SeekingIterable<SliceSlice>
 {
     private final Slice block;
     private final Comparator<Slicecomparator;
 
     private final Slice data;
     private final Slice restartPositions;
 
     public Block(Slice blockComparator<Slicecomparator)
     {
         Preconditions.checkNotNull(block"block is null");
         Preconditions.checkArgument(block.length() >= "Block is corrupt: size must be at least %s block");
         Preconditions.checkNotNull(comparator"comparator is null");
 
         block = block.slice();
         this. = block;
         this. = comparator;
 
         // Keys are prefix compressed.  Every once in a while the prefix compression is restarted and the full key is written.
         // These "restart" locations are written at the end of the file, so you can seek to key without having to read the
         // entire file sequentially.
 
         // key restart count is the last int of the block
         int restartCount = block.getInt(block.length() - );
 
         if (restartCount > 0) {
             // restarts are written at the end of the block
             int restartOffset = block.length() - (1 + restartCount) * ;
             Preconditions.checkArgument(restartOffset < block.length() - "Block is corrupt: restart offset count is greater than block size");
              = block.slice(restartOffsetrestartCount * );
 
             // data starts at 0 and extends to the restart index
              = block.slice(0, restartOffset);
         }
         else {
              = .;
              = .;
        }
    }
    public long size()
    {
        return .length();
    }
    @Override
    public BlockIterator iterator()
    {
        return new BlockIterator();
    }
New to GrepCode? Check out our FAQ X