Package arc.struct

Class IntSeq

java.lang.Object
arc.struct.IntSeq

public class IntSeq extends Object
A resizable, ordered or unordered int 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
    int[]
     
    boolean
     
    int
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    add(int value)
     
    void
    add(int value1, int value2)
     
    void
    add(int value1, int value2, int value3)
     
    void
    add(int value1, int value2, int value3, int value4)
     
    void
    addAll(int... array)
     
    void
    addAll(int[] array, int offset, int length)
     
    void
    addAll(IntSeq array)
     
    void
    addAll(IntSeq array, int offset, int length)
     
    boolean
    addUnique(int value)
    Adds a value if it was already not in this sequence.
    void
     
    boolean
    contains(int value)
     
    int
    count(int value)
     
    void
    each(Intc iterator)
     
    int[]
    ensureCapacity(int additionalCapacity)
    Increases the size of the backing array to accommodate the specified number of additional items.
    boolean
    equals(Object object)
     
    int
    Returns the first item.
    int
    get(int index)
     
    int
     
    void
    incr(int index, int value)
     
    int
    indexOf(int value)
     
    void
    insert(int index, int value)
     
    boolean
    Returns true if the array is empty.
    int
    lastIndexOf(int value)
     
    int
     
    void
    mul(int index, int value)
     
    int
    Returns the last item.
    int
    pop()
    Removes and returns the last item.
    int
    Returns a random item from the array, or zero if the array is empty.
    static IntSeq
    range(int min, int max)
     
    boolean
    Removes from this array all of elements contained in the specified array.
    int
    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(int value)
     
    protected int[]
    resize(int newSize)
     
    void
     
    void
    set(int index, int value)
     
    int[]
    setSize(int newSize)
    Sets the array size, leaving any values beyond the current size undefined.
    int[]
    Reduces the size of the backing array to the size of the actual items.
    void
     
    void
    shuffle(Rand rand)
     
    void
     
    int
    sum()
     
    void
    swap(int first, int second)
     
    int[]
     
     
    toString(String separator)
     
    void
    truncate(int newSize)
    Reduces the size of the array to the specified size.
    static IntSeq
    with(int... array)
     

    Methods inherited from class java.lang.Object

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

    • items

      public int[] items
    • size

      public int size
    • ordered

      public boolean ordered
  • Constructor Details

    • IntSeq

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

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

      public IntSeq(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.
    • IntSeq

      public IntSeq(IntSeq 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.
    • IntSeq

      public IntSeq(int[] 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.
    • IntSeq

      public IntSeq(boolean ordered, int[] 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

    • range

      public static IntSeq range(int min, int max)
    • with

      public static IntSeq with(int... array)
      See Also:
    • mode

      public int mode()
      Returns:
      the most frequently occuring element.
    • each

      public void each(Intc iterator)
    • count

      public int count(int value)
    • sum

      public int sum()
    • addUnique

      public boolean addUnique(int value)
      Adds a value if it was already not in this sequence.
      Returns:
      whether this value was not present in this sequence.
    • add

      public void add(int value)
    • add

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

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

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

      public void addAll(IntSeq array)
    • addAll

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

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

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

      public int get(int index)
    • set

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

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

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

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

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

      public boolean contains(int value)
    • indexOf

      public int indexOf(int value)
    • lastIndexOf

      public int lastIndexOf(int value)
    • removeValue

      public boolean removeValue(int value)
    • removeIndex

      public int 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(IntSeq array)
      Removes from this array all of elements contained in the specified array.
      Returns:
      true if this array was modified.
    • pop

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

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

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

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

      public void clear()
    • shrink

      public int[] 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 int[] 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 int[] setSize(int newSize)
      Sets the array size, leaving any values beyond the current size undefined.
      Returns:
      items
    • resize

      protected int[] resize(int newSize)
    • sort

      public void sort()
    • reverse

      public void reverse()
    • shuffle

      public void shuffle()
    • shuffle

      public void shuffle(Rand rand)
    • 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 int random()
      Returns a random item from the array, or zero if the array is empty.
    • toArray

      public int[] toArray()
    • hashCode

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

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

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

      public String toString(String separator)