Class DoubleMappedBigList

  • All Implemented Interfaces:
    BigList<java.lang.Double>, DoubleBigList, DoubleCollection, DoubleIterable, DoubleStack, Size64, Stack<java.lang.Double>, java.lang.Comparable<BigList<? extends java.lang.Double>>, java.lang.Iterable<java.lang.Double>, java.util.Collection<java.lang.Double>

    public class DoubleMappedBigList
    extends AbstractDoubleBigList
    A bridge between byte buffers and type-specific big lists.

    Java's memory-mapping facilities have the severe limitation of mapping at most Integer.MAX_VALUE bytes, as they expose the content of a file using a MappedByteBuffer. This class can expose a file of primitive types of arbitrary length as a BigList that is actually based on an array of MappedByteBuffers, each mapping a chunk of CHUNK_SIZE longs.

    Mapping can happen with a specified byte order: saving and mapping data in native order using methods from BinIO will enhance performance significantly.

    Instances of this class are not thread safe, but the copy() method provides a lightweight duplicate that can be read independently by another thread. Only chunks that are actually used will be duplicated lazily. If you are modifiying the content of list, however, you will need to provide external synchronization.

    Author:
    Sebastiano Vigna
    • Field Detail

      • LOG2_BYTES

        public static int LOG2_BYTES
        The logarithm of the number of bytes of the primitive type of this list.
      • LOG2_BITS

        @Deprecated
        public static int LOG2_BITS
        Deprecated.
    • Method Detail

      • map

        public static DoubleMappedBigList map​(java.nio.channels.FileChannel fileChannel)
                                       throws java.io.IOException
        Creates a new mapped big list by read-only mapping a given file channel using the standard Java (i.e., DataOutput) byte order (ByteOrder.BIG_ENDIAN).
        Parameters:
        fileChannel - the file channel that will be mapped.
        Returns:
        a new read-only mapped big list over the contents of fileChannel.
        Throws:
        java.io.IOException
        See Also:
        map(FileChannel, ByteOrder, MapMode)
      • map

        public static DoubleMappedBigList map​(java.nio.channels.FileChannel fileChannel,
                                              java.nio.ByteOrder byteOrder)
                                       throws java.io.IOException
        Creates a new mapped big list by read-only mapping a given file channel.
        Parameters:
        fileChannel - the file channel that will be mapped.
        byteOrder - a prescribed byte order.
        Returns:
        a new read-only mapped big list over the contents of fileChannel.
        Throws:
        java.io.IOException
        See Also:
        map(FileChannel, ByteOrder, MapMode)
      • map

        public static DoubleMappedBigList map​(java.nio.channels.FileChannel fileChannel,
                                              java.nio.ByteOrder byteOrder,
                                              java.nio.channels.FileChannel.MapMode mapMode)
                                       throws java.io.IOException
        Creates a new mapped big list by mapping a given file channel.
        Parameters:
        fileChannel - the file channel that will be mapped.
        byteOrder - a prescribed byte order.
        mapMode - the mapping mode: usually FileChannel.MapMode.READ_ONLY, but if intend to make the list mutable, you have to pass FileChannel.MapMode.READ_WRITE.
        Returns:
        a new mapped big list over the contents of fileChannel.
        Throws:
        java.io.IOException
      • copy

        public DoubleMappedBigList copy()
        Returns a lightweight duplicate that can be read independently by another thread.

        Only chunks that are actually used will be duplicated lazily.

        Returns:
        a lightweight duplicate that can be read independently by another thread.
      • getDouble

        public double getDouble​(long index)
        Description copied from interface: DoubleBigList
        Returns the element at the specified position.
        See Also:
        BigList.get(long)
      • getElements

        public void getElements​(long from,
                                double[] a,
                                int offset,
                                int length)
        Description copied from interface: DoubleBigList
        Copies (hopefully quickly) elements of this type-specific big list into the given array.
        Parameters:
        from - the start index (inclusive).
        a - the destination array.
        offset - the offset into the destination array where to store the first element copied.
        length - the number of elements to be copied.
      • size64

        public long size64()
        Description copied from interface: Size64
        Returns the size of this data structure as a long.
        Returns:
        the size of this data structure.