Class HugeByteArray
- java.lang.Object
-
- org.neo4j.gds.core.utils.paged.HugeArray<byte[],java.lang.Byte,HugeByteArray>
-
- org.neo4j.gds.core.utils.paged.HugeByteArray
-
- All Implemented Interfaces:
org.neo4j.gds.collections.cursor.HugeCursorSupport<byte[]>
public abstract class HugeByteArray extends HugeArray<byte[],java.lang.Byte,HugeByteArray>
A long-indexable version of a primitive byte array (byte[]
) that can contain more than 2 bn. elements.It is implemented by paging of smaller byte-arrays (
byte[][]
) to support approx. 32k bn. elements. If the provided size is small enough, an optimized view of a singlebyte[]
might be used.- The array is of a fixed size and cannot grow or shrink dynamically.
- The array is not optimized for sparseness and has a large memory overhead if the values written to it are very sparse (see
HugeSparseByteArray
for a different implementation that can profit from sparse data). - The array does not support default values and returns the same default for unset values that a regular
byte[]
does (0
).
Basic Usage
AllocationTracker allocationTracker = ...; long arraySize = 42L; HugeByteArray array = HugeByteArray.newArray(arraySize, allocationTracker); array.set(13L, 37); byte value = array.get(13L); // value = 37
-
-
Constructor Summary
Constructors Constructor Description HugeByteArray()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addTo(long index, byte value)
Adds (+
) the existing value and the provided value at the given index and stored the result into the given index.abstract byte
and(long index, byte value)
Computes the bit-wise AND (&
) of the existing value and the provided value at the given index.LongNodePropertyValues
asNodeProperties()
HugeByteArray
copyOf(long newLength)
Creates a copy of the given array.abstract void
copyTo(HugeByteArray dest, long length)
Copies the content of this array into the target array.abstract void
fill(byte value)
Assigns the specified byte value to each element.abstract byte
get(long index)
abstract byte
getAndAdd(long index, byte delta)
static long
memoryEstimation(long size)
static HugeByteArray
newArray(long size)
Creates a new array of the given size.abstract org.neo4j.gds.collections.cursor.HugeCursor<byte[]>
newCursor()
static HugeByteArray
of(byte... values)
abstract void
or(long index, byte value)
Computes the bit-wise OR (|
) of the existing value and the provided value at the given index.abstract long
release()
Destroys the data, allowing the underlying storage arrays to be collected as garbage.abstract void
set(long index, byte value)
Sets the byte value at the given index to the given value.abstract void
setAll(org.eclipse.collections.api.block.function.primitive.LongToByteFunction gen)
Set all elements using the provided generator function to compute each element.abstract long
size()
Returns the length of this array.abstract long
sizeOf()
byte[]
toArray()
-
Methods inherited from class org.neo4j.gds.core.utils.paged.HugeArray
copyFromArrayIntoSlice, toString
-
-
-
-
Method Detail
-
get
public abstract byte get(long index)
- Returns:
- the byte value at the given index
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
getAndAdd
public abstract byte getAndAdd(long index, byte delta)
-
set
public abstract void set(long index, byte value)
Sets the byte value at the given index to the given value.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
or
public abstract void or(long index, byte value)
Computes the bit-wise OR (|
) of the existing value and the provided value at the given index. If there was no previous value, the final result is set to the provided value (x | 0 == x
).- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
and
public abstract byte and(long index, byte value)
Computes the bit-wise AND (&
) of the existing value and the provided value at the given index. If there was no previous value, the final result is set to the 0 (x & 0 == 0
).- Returns:
- the now current value after the operation
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
addTo
public abstract void addTo(long index, byte value)
Adds (+
) the existing value and the provided value at the given index and stored the result into the given index. If there was no previous value, the final result is set to the provided value (x + 0 == x
).- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
setAll
public abstract void setAll(org.eclipse.collections.api.block.function.primitive.LongToByteFunction gen)
Set all elements using the provided generator function to compute each element.The behavior is identical to
Arrays.setAll(int[], java.util.function.IntUnaryOperator)
but for bytes.
-
fill
public abstract void fill(byte value)
Assigns the specified byte value to each element.The behavior is identical to
Arrays.fill(byte[], byte)
.
-
size
public abstract long size()
Returns the length of this array.If the size is greater than zero, the highest supported index is
size() - 1
The behavior is identical to calling
array.length
on primitive arrays.- Specified by:
size
in interfaceorg.neo4j.gds.collections.cursor.HugeCursorSupport<byte[]>
- Specified by:
size
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
-
sizeOf
public abstract long sizeOf()
- Specified by:
sizeOf
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
- Returns:
- the amount of memory used by the instance of this array, in bytes.
This should be the same as returned from
HugeArray.release()
without actually releasing the array.
-
release
public abstract long release()
Destroys the data, allowing the underlying storage arrays to be collected as garbage. The array is unusable after calling this method and will throwNullPointerException
s on virtually every method invocation.Note that the data might not immediately collectible if there are still cursors alive that reference this array. You have to
HugeCursor.close()
every cursor instance as well.- Specified by:
release
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
- Returns:
- the amount of memory freed, in bytes.
-
newCursor
public abstract org.neo4j.gds.collections.cursor.HugeCursor<byte[]> newCursor()
-
copyTo
public abstract void copyTo(HugeByteArray dest, long length)
Copies the content of this array into the target array.The behavior is identical to
System.arraycopy(Object, int, Object, int, int)
.- Specified by:
copyTo
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
-
toArray
public byte[] toArray()
- Specified by:
toArray
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
- Returns:
- the contents of this array as a flat java primitive array. The returned array might be shared and changes would then be reflected and visible in this array.
-
copyOf
public final HugeByteArray copyOf(long newLength)
Creates a copy of the given array. The behavior is identical toArrays.copyOf(int[], int)
.- Specified by:
copyOf
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
-
asNodeProperties
public LongNodePropertyValues asNodeProperties()
- Specified by:
asNodeProperties
in classHugeArray<byte[],java.lang.Byte,HugeByteArray>
-
newArray
public static HugeByteArray newArray(long size)
Creates a new array of the given size.
-
of
public static HugeByteArray of(byte... values)
-
memoryEstimation
public static long memoryEstimation(long size)
-
-