Class FastArray<T>

java.lang.Object
org.ddogleg.struct.FastAccess<T>
org.ddogleg.struct.FastArray<T>
All Implemented Interfaces:
Serializable

public class FastArray<T>
extends FastAccess<T>
A growable array which provides access to the raw array but does not own the elements inside of the array. When it is inexpensive to do so (O(1) operation) it will discard references to data when they are no longer needed.
See Also:
Serialized Form
  • Constructor Details

    • FastArray

      public FastArray​(Class<T> type, int initialMaxSize)
    • FastArray

      public FastArray​(Class<T> type)
  • Method Details

    • set

      public void set​(int index, T value)
    • add

      public void add​(T value)
    • remove

      public T remove​(int index)
      Description copied from class: FastAccess
      Removes an element from the queue and preserves the order of all elements. This is done by shifting elements in the array down one and placing the removed element at the old end of the list. O(N) runtime.
      Specified by:
      remove in class FastAccess<T>
      Parameters:
      index - Index of the element being removed
      Returns:
      The object removed.
    • removeSwap

      public T removeSwap​(int index)
      Description copied from class: FastAccess
      Removes the specified index from the array by swapping it with last element. Does not preserve order but has a runtime of O(1).
      Specified by:
      removeSwap in class FastAccess<T>
      Parameters:
      index - The index to be removed.
      Returns:
      The removed object
    • remove

      public boolean remove​(T target)
      Searches for the object and removes it if it's contained in the list. O(N) operation.
      Parameters:
      target - Object to be removed
      Returns:
      true if it was removed or false if it was not found
    • removeTail

      public T removeTail()
    • reset

      public void reset()
      Sets the size of the list to zero. External references are not modified.
    • clear

      public void clear()
      Sets the size of the list to zero and removes all internal references inside the current array.
    • reserve

      public void reserve​(int length)
      Ensures that the internal array has at least `length` elements. If it does not then a new internal array is created with the specified length and elements from the old are copied into the new. The `size` does not change.
      Parameters:
      length - Requested minimum internal array length
    • reserve

      public void reserve​(int length, boolean copy)
    • resize

      public void resize​(int length)
      Changes the size to the specified length. Equivalent to calling reserve(int) and this.size = N.
      Parameters:
      length - The new size of the queue
    • resize

      public void resize​(int length, T value)
      Changes the size and fills each element with this value
    • addAll

      public void addAll​(FastAccess<T> list)
    • add

      public void add​(T[] array, int first, int length)
    • setTail

      public void setTail​(int index, T value)
    • addAll

      public void addAll​(List<T> list)
    • toList

      public List<T> toList()
      Returns a wrapper around FastQueue that allows it to act as a read only list. There is little overhead in using this interface. NOTE: The same instead of a list is returned each time. Be careful when writing concurrent code and create a copy.
      Specified by:
      toList in class FastAccess<T>
      Returns:
      List wrapper.