Package arc.struct

Class FloatSeq

java.lang.Object
arc.struct.FloatSeq

public class FloatSeq extends Object
A resizable, ordered or unordered float array. Avoids the boxing that occurs with ArrayList. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float[]
     
    boolean
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an ordered array with a capacity of 16.
    FloatSeq(boolean ordered, float[] array, int startIndex, int count)
    Creates a new array containing the elements in the specified array.
    FloatSeq(boolean ordered, int capacity)
     
    FloatSeq(float[] array)
    Creates a new ordered array containing the elements in the specified array.
    FloatSeq(int capacity)
    Creates an ordered array with the specified capacity.
    Creates a new array containing the elements in the specific array.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(float value)
     
    void
    add(float value1, float value2)
     
    void
    add(float value1, float value2, float value3)
     
    void
    add(float value1, float value2, float value3, float value4)
     
    void
    addAll(float... array)
     
    void
    addAll(float[] array, int offset, int length)
     
    void
     
    void
    addAll(FloatSeq array, int offset, int length)
     
    void
     
    boolean
    contains(float value)
     
    float[]
    ensureCapacity(int additionalCapacity)
    Increases the size of the backing array to accommodate the specified number of additional items.
    boolean
    equals(Object object)
     
    boolean
    equals(Object object, float epsilon)
     
    float
    Returns the first item.
    float
    get(int index)
     
    int
     
    void
    incr(int index, float value)
     
    int
    indexOf(float value)
     
    void
    insert(int index, float value)
     
    boolean
    Returns true if the array is empty.
    int
    lastIndexOf(float value)
     
    void
    mul(int index, float value)
     
    float
    Returns the last item.
    float
    pop()
    Removes and returns the last item.
    float
    Returns a random item from the array, or zero if the array is empty.
    boolean
    Removes from this array all of elements contained in the specified array.
    float
    removeIndex(int index)
    Removes and returns the item at the specified index.
    void
    removeRange(int start, int end)
    Removes the items between the specified indices, inclusive.
    boolean
    removeValue(float value)
     
    protected float[]
    resize(int newSize)
     
    void
     
    void
    set(int index, float value)
     
    float[]
    setSize(int newSize)
    Sets the array size, leaving any values beyond the current size undefined.
    float[]
    Reduces the size of the backing array to the size of the actual items.
    void
     
    void
     
    float
    sum()
     
    void
    swap(int first, int second)
     
    float[]
     
     
    toString(String separator)
     
    Converts this float array to a Vec2 array, with pairs used for coordinates.
    void
    truncate(int newSize)
    Reduces the size of the array to the specified size.
    static FloatSeq
    with(float... array)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • items

      public float[] items
    • size

      public int size
    • ordered

      public boolean ordered
  • Constructor Details

    • FloatSeq

      public FloatSeq()
      Creates an ordered array with a capacity of 16.
    • FloatSeq

      public FloatSeq(int capacity)
      Creates an ordered array with the specified capacity.
    • FloatSeq

      public FloatSeq(boolean ordered, int capacity)
      Parameters:
      ordered - If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
      capacity - Any elements added beyond this will cause the backing array to be grown.
    • FloatSeq

      public FloatSeq(FloatSeq array)
      Creates a new array containing the elements in the specific array. The new array will be ordered if the specific array is ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
    • FloatSeq

      public FloatSeq(float[] array)
      Creates a new ordered array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
    • FloatSeq

      public FloatSeq(boolean ordered, float[] array, int startIndex, int count)
      Creates a new array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
      Parameters:
      ordered - If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
  • Method Details

    • with

      public static FloatSeq with(float... array)
      See Also:
    • toVec2Array

      public Seq<Vec2> toVec2Array()
      Converts this float array to a Vec2 array, with pairs used for coordinates.
    • add

      public void add(float value)
    • add

      public void add(float value1, float value2)
    • add

      public void add(float value1, float value2, float value3)
    • add

      public void add(float value1, float value2, float value3, float value4)
    • addAll

      public void addAll(FloatSeq array)
    • addAll

      public void addAll(FloatSeq array, int offset, int length)
    • addAll

      public void addAll(float... array)
    • addAll

      public void addAll(float[] array, int offset, int length)
    • get

      public float get(int index)
    • set

      public void set(int index, float value)
    • incr

      public void incr(int index, float value)
    • mul

      public void mul(int index, float value)
    • insert

      public void insert(int index, float value)
    • swap

      public void swap(int first, int second)
    • contains

      public boolean contains(float value)
    • indexOf

      public int indexOf(float value)
    • lastIndexOf

      public int lastIndexOf(float value)
    • removeValue

      public boolean removeValue(float value)
    • removeIndex

      public float removeIndex(int index)
      Removes and returns the item at the specified index.
    • removeRange

      public void removeRange(int start, int end)
      Removes the items between the specified indices, inclusive.
    • removeAll

      public boolean removeAll(FloatSeq array)
      Removes from this array all of elements contained in the specified array.
      Returns:
      true if this array was modified.
    • pop

      public float pop()
      Removes and returns the last item.
    • peek

      public float peek()
      Returns the last item.
    • first

      public float first()
      Returns the first item.
    • isEmpty

      public boolean isEmpty()
      Returns true if the array is empty.
    • clear

      public void clear()
    • sum

      public float sum()
    • shrink

      public float[] shrink()
      Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.
      Returns:
      items
    • ensureCapacity

      public float[] ensureCapacity(int additionalCapacity)
      Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.
      Returns:
      items
    • setSize

      public float[] setSize(int newSize)
      Sets the array size, leaving any values beyond the current size undefined.
      Returns:
      items
    • resize

      protected float[] resize(int newSize)
    • sort

      public void sort()
    • reverse

      public void reverse()
    • shuffle

      public void shuffle()
    • truncate

      public void truncate(int newSize)
      Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.
    • random

      public float random()
      Returns a random item from the array, or zero if the array is empty.
    • toArray

      public float[] toArray()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(Object object, float epsilon)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(String separator)