Class 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 single T[] 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
      NodeProperties asNodeProperties()  
      abstract HugeObjectArray<T> copyOf​(long newLength, AllocationTracker allocationTracker)
      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, AllocationTracker allocationTracker)
      Creates a new array of the given size, tracking the memory requirements into the given AllocationTracker.
      abstract HugeCursor<T[]> newCursor()
      Returns a new HugeCursor 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 is null, attempts to compute its value using the given supplier and enters it into this array unless null.
      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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HugeObjectArray

        public HugeObjectArray()
    • 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 within size()
      • 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 within size()
      • putIfAbsent

        public abstract T putIfAbsent​(long index,
                                      java.util.function.Supplier<T> supplier)
        If the value at the given index is null, attempts to compute its value using the given supplier and enters it into this array unless null.
        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 within size()
      • 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 interface HugeCursorSupport<T>
        Specified by:
        size in class HugeArray<T[],​T,​HugeObjectArray<T>>
      • sizeOf

        public abstract long sizeOf()
        Specified by:
        sizeOf in class HugeArray<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 throw NullPointerExceptions 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.

        The amount is not removed from the AllocationTracker that had been provided in the constructor.

        Specified by:
        release in class HugeArray<T[],​T,​HugeObjectArray<T>>
        Returns:
        the amount of memory freed, in bytes.
      • 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).

        Specified by:
        copyTo in class HugeArray<T[],​T,​HugeObjectArray<T>>
      • toArray

        public abstract T[] toArray()
        Specified by:
        toArray in class HugeArray<T[],​T,​HugeObjectArray<T>>
        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.
      • newArray

        public static <T> HugeObjectArray<T> newArray​(java.lang.Class<T> componentClass,
                                                      long size,
                                                      AllocationTracker allocationTracker)
        Creates a new array of the given size, tracking the memory requirements into the given AllocationTracker. The tracker is no longer referenced, as the arrays do not dynamically change their 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)