Package it.unimi.dsi.util
Class ByteBufferLongBigList
- java.lang.Object
-
- java.util.AbstractCollection<Long>
-
- it.unimi.dsi.fastutil.longs.AbstractLongCollection
-
- it.unimi.dsi.fastutil.longs.AbstractLongBigList
-
- it.unimi.dsi.util.ByteBufferLongBigList
-
- All Implemented Interfaces:
BigList<Long>,LongBigList,LongCollection,LongIterable,LongStack,Size64,Stack<Long>,FlyweightPrototype<ByteBufferLongBigList>,Comparable<BigList<? extends Long>>,Iterable<Long>,Collection<Long>
public class ByteBufferLongBigList extends AbstractLongBigList implements FlyweightPrototype<ByteBufferLongBigList>
A bridge between byte buffers and long big lists.Java's memory-mapping facilities have the severe limitation of mapping at most
Integer.MAX_VALUEbytes, as they expose the content of a file using aMappedByteBuffer. This class can expose a file of longs of arbitrary length as a LongBigList that is actually based on an array ofMappedByteBuffers, each mapping a chunk ofCHUNK_SIZElongs.Instances of this class are not thread safe, but the
copy()method provides a lightweight duplicate that can be accessed independently by another thread. Only chunks that are actually used will be duplicated lazily.- Author:
- Sebastiano Vigna
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class it.unimi.dsi.fastutil.longs.AbstractLongBigList
AbstractLongBigList.LongSubList
-
-
Field Summary
Fields Modifier and Type Field Description static longCHUNK_SIZEThe size in longs of a chunk created bymap(FileChannel, ByteOrder, FileChannel.MapMode).
-
Constructor Summary
Constructors Modifier Constructor Description ByteBufferLongBigList(ByteBuffer byteBuffer)Creates a new byte-buffer long big list from a singleByteBuffer.protectedByteBufferLongBigList(ByteBuffer[] byteBuffer, long size, boolean[] readyToUse)Creates a new byte-buffer long big list.
-
Method Summary
Modifier and Type Method Description ByteBufferLongBigListcopy()Returns a copy of this object, sharing state with this object as much as possible.longgetLong(long index)static ByteBufferLongBigListmap(FileChannel fileChannel)Creates a new byte-buffer long big list by read-only mapping a given file channel using the standard Java (i.e.,DataOutput) byte order (ByteOrder.BIG_ENDIAN).static ByteBufferLongBigListmap(FileChannel fileChannel, ByteOrder byteOrder)Creates a new byte-buffer long big list by read-only mapping a given file channel.static ByteBufferLongBigListmap(FileChannel fileChannel, ByteOrder byteOrder, FileChannel.MapMode mapMode)Creates a new byte-buffer long big list by mapping a given file channel.longset(long index, long value)longsize64()-
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongBigList
add, add, add, addAll, addAll, addAll, addAll, addAll, addAll, addElements, addElements, clear, compareTo, contains, ensureIndex, ensureRestrictedIndex, equals, get, getElements, hashCode, indexOf, indexOf, iterator, lastIndexOf, lastIndexOf, listIterator, listIterator, peek, peekLong, pop, popLong, push, push, rem, remove, removeElements, removeLong, set, size, size, subList, top, topLong, toString
-
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, contains, containsAll, remove, removeAll, retainAll, toArray, toLongArray, toLongArray
-
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
containsAll, isEmpty, parallelStream, removeAll, retainAll, spliterator, stream, toArray, toArray, toArray
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongCollection
add, contains, containsAll, remove, removeAll, removeIf, removeIf, retainAll, toArray, toLongArray, toLongArray
-
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongIterable
forEach, forEach
-
-
-
-
Field Detail
-
CHUNK_SIZE
public static final long CHUNK_SIZE
The size in longs of a chunk created bymap(FileChannel, ByteOrder, FileChannel.MapMode).
-
-
Constructor Detail
-
ByteBufferLongBigList
public ByteBufferLongBigList(ByteBuffer byteBuffer)
Creates a new byte-buffer long big list from a singleByteBuffer.- Parameters:
byteBuffer- the underlying byte buffer.
-
ByteBufferLongBigList
protected ByteBufferLongBigList(ByteBuffer[] byteBuffer, long size, boolean[] readyToUse)
Creates a new byte-buffer long big list.- Parameters:
byteBuffer- the underlying byte buffers.size- the overall number of longs in the underlying byte buffers (i.e., the sum of the capacities of the byte buffers divided by eight).readyToUse- an array parallel tobyteBufferspecifying which buffers do not need to be duplicated before being used (the process will happen lazily); the array will be used internally by the newly created byte-buffer long big list.
-
-
Method Detail
-
map
public static ByteBufferLongBigList map(FileChannel fileChannel) throws IOException
Creates a new byte-buffer long 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 byte-buffer long big list over the contents of
fileChannel. - Throws:
IOException- See Also:
map(FileChannel, ByteOrder, MapMode)
-
map
public static ByteBufferLongBigList map(FileChannel fileChannel, ByteOrder byteOrder) throws IOException
Creates a new byte-buffer long 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 byte-buffer long big list over the contents of
fileChannel. - Throws:
IOException- See Also:
map(FileChannel, ByteOrder, MapMode)
-
map
public static ByteBufferLongBigList map(FileChannel fileChannel, ByteOrder byteOrder, FileChannel.MapMode mapMode) throws IOException
Creates a new byte-buffer long 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: usuallyFileChannel.MapMode.READ_ONLY, but if intend to make the list mutable, you have to passFileChannel.MapMode.READ_WRITE.- Returns:
- a new byte-buffer long big list over the contents of
fileChannel. - Throws:
IOException
-
copy
public ByteBufferLongBigList copy()
Description copied from interface:FlyweightPrototypeReturns a copy of this object, sharing state with this object as much as possible.- Specified by:
copyin interfaceFlyweightPrototype<ByteBufferLongBigList>- Returns:
- a copy of this object, sharing state with this object as much as possible.
-
getLong
public long getLong(long index)
- Specified by:
getLongin interfaceLongBigList
-
set
public long set(long index, long value)- Specified by:
setin interfaceLongBigList- Overrides:
setin classAbstractLongBigList
-
-