Ejemplo n.º 1
0
 @Override
 public int getIntArray(int row, int[] intArray) {
   int startOffset = computeStartOffset(row);
   int length = computeLength(startOffset);
   for (int i = 0; i < length; i++) {
     intArray[i] = rawDataReader.getInt(startOffset + i, 0);
   }
   return length;
 }
Ejemplo n.º 2
0
  public FixedBitSkipListSCMVReader(
      File file,
      int numDocs,
      int totalNumValues,
      int columnSizeInBits,
      boolean signed,
      boolean isMmap)
      throws Exception {
    this.numDocs = numDocs;
    this.totalNumValues = totalNumValues;
    float averageValuesPerDoc = totalNumValues / numDocs;
    this.docsPerChunk = (int) (Math.ceil(PREFERRED_NUM_VALUES_PER_CHUNK / averageValuesPerDoc));
    this.numChunks = (numDocs + docsPerChunk - 1) / docsPerChunk;
    chunkOffsetHeaderSize = numChunks * SIZE_OF_INT * NUM_COLS_IN_HEADER;
    bitsetSize = (totalNumValues + 7) / 8;
    rawDataSize = Ints.checkedCast(((long) totalNumValues * columnSizeInBits + 7) / 8);
    totalSize = chunkOffsetHeaderSize + bitsetSize + rawDataSize;
    raf = new RandomAccessFile(file, "rw");
    this.isMmap = isMmap;
    if (isMmap) {
      chunkOffsetsBuffer =
          raf.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, chunkOffsetHeaderSize).load();
      bitsetBuffer =
          raf.getChannel()
              .map(FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize, bitsetSize)
              .load();
      rawDataBuffer =
          raf.getChannel()
              .map(FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize + bitsetSize, rawDataSize)
              .load();

      chunkOffsetsReader =
          new FixedByteWidthRowColDataFileReader(
              chunkOffsetsBuffer, numDocs, NUM_COLS_IN_HEADER, new int[] {SIZE_OF_INT});

      customBitSet = CustomBitSet.withByteBuffer(bitsetSize, bitsetBuffer);
      rawDataReader =
          FixedBitWidthRowColDataFileReader.forByteBuffer(
              rawDataBuffer,
              totalNumValues,
              1,
              new int[] {columnSizeInBits},
              new boolean[] {signed});
    } else {
      chunkOffsetsBuffer = ByteBuffer.allocateDirect(chunkOffsetHeaderSize);
      raf.getChannel().read(chunkOffsetsBuffer);
      chunkOffsetsReader =
          new FixedByteWidthRowColDataFileReader(
              chunkOffsetsBuffer, numDocs, NUM_COLS_IN_HEADER, new int[] {SIZE_OF_INT});
      bitsetBuffer = ByteBuffer.allocateDirect(bitsetSize);
      raf.getChannel().read(bitsetBuffer);
      customBitSet = CustomBitSet.withByteBuffer(bitsetSize, bitsetBuffer);
      rawDataBuffer = ByteBuffer.allocateDirect(rawDataSize);
      raf.getChannel().read(rawDataBuffer);
      rawDataReader =
          FixedBitWidthRowColDataFileReader.forByteBuffer(
              rawDataBuffer,
              totalNumValues,
              1,
              new int[] {columnSizeInBits},
              new boolean[] {signed});
      raf.close();
    }
  }