com.indeed.util.mmap.DirectMemory Java Examples

The following examples show how to use com.indeed.util.mmap.DirectMemory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableWriter.java    From mph-table with Apache License 2.0 5 votes vote down vote up
private static <K, V> Select sizesToSelect(final TableConfig<K, V> config,
                                           final File tempSizes,
                                           final long dataSize) throws IOException {
    final long numEntries = tempSizes.length() / 4;
    try (final MMapBuffer sizes = new MMapBuffer(tempSizes, 0L, numEntries * 4, FileChannel.MapMode.READ_ONLY, ByteOrder.nativeOrder())) {
        final DirectMemory sizesMemory = sizes.memory();
        final long maxValue = config.compressOffset(dataSize, numEntries);
        final BitVector bits = LongArrayBitVector.ofLength(maxValue);
        for (long i = 0, offset = 0; i < numEntries; offset += sizesMemory.getInt(i * 4), ++i) {
            final long value = config.compressOffset(offset, i);
            bits.set(value);
        }
        return new HintedBsearchSelect(new Rank9(bits));
    }
}
 
Example #2
Source File: NativeMetricRegroupInternals.java    From imhotep with Apache License 2.0 5 votes vote down vote up
public static void calculateGroups(final int min, final int max, final long magicNumber, final int numBuckets, final int n, int[] valBuf, int[] docGroupBuffer, DirectMemory nativeValBuf, DirectMemory nativeDocGroupBuffer) {
    final long valBufAddress = nativeValBuf.getAddress();
    UNSAFE.copyMemory(valBuf, INT_ARRAY_BASE_OFFSET, null, valBufAddress, 4*n);
    final long docGroupBufferAddress = nativeDocGroupBuffer.getAddress();
    calculateGroups(min, max, magicNumber, numBuckets, n, valBufAddress, docGroupBufferAddress);
    UNSAFE.copyMemory(null, docGroupBufferAddress, docGroupBuffer, INT_ARRAY_BASE_OFFSET, 4*n);
}
 
Example #3
Source File: BlockCompressedRecordFile.java    From lsmtree with Apache License 2.0 5 votes vote down vote up
public static @Nullable byte[] getMetadata(File file) throws IOException {
    final long length = file.length();
    final MMapBuffer buffer = new MMapBuffer(file, 0, length, FileChannel.MapMode.READ_ONLY, ByteOrder.BIG_ENDIAN);
    final DirectMemory memory = buffer.memory();
    final int metadataLength = memory.getInt(length - 12);
    if (metadataLength == Integer.MAX_VALUE) return null;
    final byte[] metadata = new byte[metadataLength];
    memory.getBytes(length-12-metadataLength, metadata);
    return metadata;
}