Package arc.struct

Class LongSeq

java.lang.Object
arc.struct.LongSeq

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

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

    Modifier and Type
    Method
    Description
    void
    add(long value)
     
    void
    add(long value1, long value2)
     
    void
    add(long value1, long value2, long value3)
     
    void
    add(long value1, long value2, long value3, long value4)
     
    void
    addAll(long... array)
     
    void
    addAll(long[] array, int offset, int length)
     
    void
    addAll(LongSeq array)
     
    void
    addAll(LongSeq array, int offset, int length)
     
    void
     
    boolean
    contains(long value)
     
    long[]
    ensureCapacity(int additionalCapacity)
    Increases the size of the backing array to accommodate the specified number of additional items.
    boolean
    equals(Object object)
     
    long
    Returns the first item.
    long
    get(int index)
     
    int
     
    void
    incr(int index, long value)
     
    int
    indexOf(long value)
     
    void
    insert(int index, long value)
     
    boolean
    Returns true if the array is empty.
    int
    lastIndexOf(char value)
     
    void
    mul(int index, long value)
     
    long
    Returns the last item.
    long
    pop()
    Removes and returns the last item.
    long
    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.
    long
    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(long value)
     
    protected long[]
    resize(int newSize)
     
    void
     
    void
    set(int index, long value)
     
    long[]
    setSize(int newSize)
    Sets the array size, leaving any values beyond the current size undefined.
    long[]
    Reduces the size of the backing array to the size of the actual items.
    void
     
    void
     
    void
    swap(int first, int second)
     
    long[]
     
     
    toString(String separator)
     
    void
    truncate(int newSize)
    Reduces the size of the array to the specified size.
    static LongSeq
    with(long... array)
     

    Methods inherited from class java.lang.Object

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

    • items

      public long[] items
    • size

      public int size
    • ordered

      public boolean ordered
  • Constructor Details

    • LongSeq

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

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

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

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

      public LongSeq(long[] 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.
    • LongSeq

      public LongSeq(boolean ordered, long[] 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 LongSeq with(long... array)
      See Also:
    • add

      public void add(long value)
    • add

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

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

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

      public void addAll(LongSeq array)
    • addAll

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

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

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

      public long get(int index)
    • set

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

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

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

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

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

      public boolean contains(long value)
    • indexOf

      public int indexOf(long value)
    • lastIndexOf

      public int lastIndexOf(char value)
    • removeValue

      public boolean removeValue(long value)
    • removeIndex

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

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

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

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

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

      public void clear()
    • shrink

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

      protected long[] 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 long random()
      Returns a random item from the array, or zero if the array is empty.
    • toArray

      public long[] 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)