Class HugeObjectArray<T>
- java.lang.Object
-
- org.neo4j.gds.core.utils.paged.HugeArray<T[],T,HugeObjectArray<T>>
-
- org.neo4j.gds.core.utils.paged.HugeObjectArray<T>
-
- All Implemented Interfaces:
HugeCursorSupport<T[]>
public abstract class HugeObjectArray<T> extends HugeArray<T[],T,HugeObjectArray<T>>
A long-indexable version of a Object array (T[]
) that can contain more than 2 bn. elements.It is implemented by paging of smaller object-arrays (
T[][]
) to support approx. 32k bn. elements. If the provided size is small enough, an optimized view of a singleT[]
might be used.- The array is of a fixed size and cannot grow or shrink dynamically.
- The array does not support default values and returns the same default for unset values that a regular
T[]
does (null
).
Basic Usage
AllocationTracker allocationTracker = ...; long arraySize = 42L; HugeObjectArray<String> array = HugeObjectArray.newArray(String.class, arraySize, allocationTracker); array.set(13L, "37"); String value = array.get(13L); // value = "37"
-
-
Constructor Summary
Constructors Constructor Description HugeObjectArray()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description NodePropertyValues
asNodeProperties()
abstract HugeObjectArray<T>
copyOf(long newLength)
Creates a copy of the given array.abstract void
copyTo(HugeObjectArray<T> dest, long length)
Copies the content of this array into the target array.abstract void
fill(T value)
Assigns the specified value to each element.abstract T
get(long index)
static org.neo4j.gds.core.utils.mem.MemoryEstimation
memoryEstimation(long objectEstimation)
static long
memoryEstimation(long arraySize, long objectSize)
static org.neo4j.gds.core.utils.mem.MemoryEstimation
memoryEstimation(org.neo4j.gds.core.utils.mem.MemoryEstimation objectEstimation)
static <T> HugeObjectArray<T>
newArray(java.lang.Class<T> componentClass, long size)
Creates a new array of the given size.abstract HugeCursor<T[]>
newCursor()
Returns a newHugeCursor
for this array.static <T> HugeObjectArray<T>
of(T... values)
abstract T
putIfAbsent(long index, java.util.function.Supplier<T> supplier)
If the value at the given index isnull
, attempts to compute its value using the given supplier and enters it into this array unlessnull
.abstract long
release()
Destroys the data, allowing the underlying storage arrays to be collected as garbage.abstract void
set(long index, T value)
Sets the value at the given index to the given value.abstract void
setAll(java.util.function.LongFunction<T> 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()
abstract T[]
toArray()
-
Methods inherited from class org.neo4j.gds.core.utils.paged.HugeArray
copyFromArrayIntoSlice, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.neo4j.gds.core.utils.paged.HugeCursorSupport
initCursor, initCursor
-
-
-
-
Method Detail
-
get
public abstract T get(long index)
- Returns:
- the value at the given index
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
set
public abstract void set(long index, T value)
Sets the value at the given index to the given value.- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
putIfAbsent
public abstract T putIfAbsent(long index, java.util.function.Supplier<T> supplier)
If the value at the given index isnull
, attempts to compute its value using the given supplier and enters it into this array unlessnull
.- Parameters:
index
- index at which the specified value is to be associated- Returns:
- the current (existing or computed) value associated with the specified index, or null if the computed value is null
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the index is not withinsize()
-
setAll
public abstract void setAll(java.util.function.LongFunction<T> gen)
Set all elements using the provided generator function to compute each element.The behavior is identical to
Arrays.setAll(Object[], java.util.function.IntFunction)
.
-
fill
public abstract void fill(T value)
Assigns the specified value to each element.The behavior is identical to
Arrays.fill(Object[], Object)
.
-
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 interfaceHugeCursorSupport<T>
- Specified by:
size
in classHugeArray<T[],T,HugeObjectArray<T>>
-
sizeOf
public abstract long sizeOf()
- Specified by:
sizeOf
in classHugeArray<T[],T,HugeObjectArray<T>>
- 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.
-
newCursor
public abstract HugeCursor<T[]> newCursor()
Returns a newHugeCursor
for this array. The cursor is not positioned and in an invalid state. To position the cursor you must callHugeCursorSupport.initCursor(HugeCursor)
orHugeCursorSupport.initCursor(HugeCursor, long, long)
. Then the cursor needs to be put in a valid state by callingHugeCursor.next()
. Obtaining aHugeCursor
for an empty array (whereHugeCursorSupport.size()
returns0
) is undefined and might result in aNullPointerException
or anotherRuntimeException
.
-
copyTo
public abstract void copyTo(HugeObjectArray<T> 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)
.
-
copyOf
public abstract HugeObjectArray<T> copyOf(long newLength)
Creates a copy of the given array. The behavior is identical toArrays.copyOf(int[], int)
.
-
toArray
public abstract T[] toArray()
-
asNodeProperties
public NodePropertyValues asNodeProperties()
- Specified by:
asNodeProperties
in classHugeArray<T[],T,HugeObjectArray<T>>
-
newArray
public static <T> HugeObjectArray<T> newArray(java.lang.Class<T> componentClass, long size)
Creates a new array of the given size.
-
of
@SafeVarargs public static <T> HugeObjectArray<T> of(T... values)
-
memoryEstimation
public static long memoryEstimation(long arraySize, long objectSize)
-
memoryEstimation
public static org.neo4j.gds.core.utils.mem.MemoryEstimation memoryEstimation(org.neo4j.gds.core.utils.mem.MemoryEstimation objectEstimation)
-
memoryEstimation
public static org.neo4j.gds.core.utils.mem.MemoryEstimation memoryEstimation(long objectEstimation)
-
-