Class HugeLongArray
- java.lang.Object
-
- org.neo4j.gds.core.utils.paged.HugeArray<long[],java.lang.Long,HugeLongArray>
-
- org.neo4j.gds.core.utils.paged.HugeLongArray
-
- All Implemented Interfaces:
HugeCursorSupport<long[]>
public abstract class HugeLongArray extends HugeArray<long[],java.lang.Long,HugeLongArray>
A long-indexable version of a primitive long array (long[]) that can contain more than 2 bn. elements.It is implemented by paging of smaller long-arrays (
long[][]) to support approx. 32k bn. elements. If the provided size is small enough, an optimized view of a singlelong[]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
HugeSparseLongArrayfor 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
long[]does (0).
Basic Usage
AllocationTracker allocationTracker = ...; long arraySize = 42L; HugeLongArray array = HugeLongArray.newArray(arraySize, allocationTracker); array.set(13L, 37L); long value = array.get(13L); // value = 37L
-
-
Constructor Summary
Constructors Constructor Description HugeLongArray()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddTo(long index, long value)Adds (+) the existing value and the provided value at the given index and stored the result into the given index.abstract longand(long index, long value)Computes the bit-wise AND (&) of the existing value and the provided value at the given index.LongNodePropertyValuesasNodeProperties()abstract longbinarySearch(long searchValue)Find the index where(values[idx] <= searchValue) && (values[idx + 1] > searchValue).HugeLongArraycopyOf(long newLength)Creates a copy of the given array.abstract voidcopyTo(HugeLongArray dest, long length)Copies the content of this array into the target array.abstract voidfill(long value)Assigns the specified long value to each element.abstract longget(long index)static longmemoryEstimation(long size)static HugeLongArraynewArray(long size)Creates a new array of the given size.abstract HugeCursor<long[]>newCursor()Returns a newHugeCursorfor this array.static HugeLongArrayof(long... values)static HugeLongArrayof(long[][] array, long size)abstract voidor(long index, long value)Computes the bit-wise OR (|) of the existing value and the provided value at the given index.abstract longrelease()Destroys the data, allowing the underlying storage arrays to be collected as garbage.abstract voidset(long index, long value)Sets the long value at the given index to the given value.abstract voidsetAll(java.util.function.LongUnaryOperator gen)Set all elements using the provided generator function to compute each element.abstract longsize()Returns the length of this array.abstract longsizeOf()long[]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 long get(long index)
- Returns:
- the long value at the given index
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if the index is not withinsize()
-
set
public abstract void set(long index, long value)Sets the long 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, long 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 long and(long index, long 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, long 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(java.util.function.LongUnaryOperator gen)
Set all elements using the provided generator function to compute each element.The behavior is identical to
Arrays.setAll(long[], java.util.function.IntToLongFunction).
-
fill
public abstract void fill(long value)
Assigns the specified long value to each element.The behavior is identical to
Arrays.fill(long[], long).
-
size
public abstract long size()
Returns the length of this array.If the size is greater than zero, the highest supported index is
size() - 1The behavior is identical to calling
array.lengthon primitive arrays.- Specified by:
sizein interfaceHugeCursorSupport<long[]>- Specified by:
sizein classHugeArray<long[],java.lang.Long,HugeLongArray>
-
sizeOf
public abstract long sizeOf()
- Specified by:
sizeOfin classHugeArray<long[],java.lang.Long,HugeLongArray>- 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.
-
binarySearch
public abstract long binarySearch(long searchValue)
Find the index where(values[idx] <= searchValue) && (values[idx + 1] > searchValue). The result differs from that ofArrays.binarySearch(long[], long)in that this method returns a positive index even if the array does not directly contain the searched value. It returns -1 iff the value is smaller than the smallest one in 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 throwNullPointerExceptions 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:
releasein classHugeArray<long[],java.lang.Long,HugeLongArray>- Returns:
- the amount of memory freed, in bytes.
-
newCursor
public abstract HugeCursor<long[]> newCursor()
Returns a newHugeCursorfor 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 aHugeCursorfor an empty array (whereHugeCursorSupport.size()returns0) is undefined and might result in aNullPointerExceptionor anotherRuntimeException.
-
copyTo
public abstract void copyTo(HugeLongArray 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:
copyToin classHugeArray<long[],java.lang.Long,HugeLongArray>
-
copyOf
public final HugeLongArray copyOf(long newLength)
Creates a copy of the given array. The behavior is identical toArrays.copyOf(int[], int).- Specified by:
copyOfin classHugeArray<long[],java.lang.Long,HugeLongArray>
-
toArray
public long[] toArray()
- Specified by:
toArrayin classHugeArray<long[],java.lang.Long,HugeLongArray>- 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.
-
asNodeProperties
public LongNodePropertyValues asNodeProperties()
- Specified by:
asNodePropertiesin classHugeArray<long[],java.lang.Long,HugeLongArray>
-
newArray
public static HugeLongArray newArray(long size)
Creates a new array of the given size.
-
memoryEstimation
public static long memoryEstimation(long size)
-
of
public static HugeLongArray of(long... values)
-
of
public static HugeLongArray of(long[][] array, long size)
-
-