Package squidpony.squidmath
Class ShortVLA
java.lang.Object
squidpony.squidmath.ShortVLA
- All Implemented Interfaces:
Serializable
public class ShortVLA extends Object implements Serializable
A resizable, ordered or unordered short variable-length array. Avoids the boxing that occurs with
Was called IntArray in libGDX; to avoid confusion with the fixed-length primitive array type, VLA (variable-length array) was chosen as a different name. Also uses short instead of int, of course. Copied from LibGDX by Tommy Ettinger on 10/1/2015.
ArrayList<Short>
.
If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed
element's position). Used internally by CoordPacker, and unlikely to be used outside of it.
Was called IntArray in libGDX; to avoid confusion with the fixed-length primitive array type, VLA (variable-length array) was chosen as a different name. Also uses short instead of int, of course. Copied from LibGDX by Tommy Ettinger on 10/1/2015.
- Author:
- Nathan Sweet
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ShortVLA()
Creates an ordered array with a capacity of 16.ShortVLA(boolean ordered, int capacity)
ShortVLA(boolean ordered, short[] array, int startIndex, int count)
Creates a new array containing the elements in the specified array.ShortVLA(int capacity)
Creates an ordered array with the specified capacity.ShortVLA(int[] array)
Creates a new ordered array containing the elements in the specified array, converted to short.ShortVLA(short[] array)
Creates a new ordered array containing the elements in the specified array.ShortVLA(ShortVLA array)
Creates a new array containing the elements in the specific array. -
Method Summary
Modifier and Type Method Description void
add(short value)
void
addAll(int[] array)
void
addAll(short... array)
void
addAll(short[] array, int offset, int length)
void
addAll(ShortVLA array)
void
addAll(ShortVLA array, int offset, int length)
void
addFractionRange(int start, int end, int fraction)
void
addRange(int start, int end)
int[]
asInts()
void
clear()
boolean
contains(short value)
short[]
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to accommodate the specified number of additional items.boolean
equals(Object object)
short
first()
Returns the first item.short
get(int index)
int
hashCode()
void
incr(int index, short value)
Adds value to the item in the ShortVLA at index.int
indexOf(short value)
void
insert(int index, short value)
int
lastIndexOf(short value)
void
mul(int index, short value)
short
peek()
Returns the last item.short
pop()
Removes and returns the last item.boolean
removeAll(ShortVLA array)
Removes from this array all of elements contained in the specified array.short
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(short value)
protected short[]
resize(int newSize)
void
reverse()
void
set(int index, short value)
short[]
shrink()
Reduces the size of the backing array to the size of the actual items.void
sort()
void
swap(int first, int second)
short[]
toArray()
String
toString()
String
toString(String separator)
void
truncate(int newSize)
Reduces the size of the array to the specified size.static ShortVLA
with(short... array)
-
Field Details
-
Constructor Details
-
ShortVLA
public ShortVLA()Creates an ordered array with a capacity of 16. -
ShortVLA
Creates an ordered array with the specified capacity. -
ShortVLA
- 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.
-
ShortVLA
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. -
ShortVLA
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. -
ShortVLA
Creates a new ordered array containing the elements in the specified array, converted to short. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown. -
ShortVLA
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
-
add
-
addAll
-
addAll
-
addAll
-
addAll
-
addAll
-
addRange
-
addFractionRange
-
get
-
set
-
incr
Adds value to the item in the ShortVLA at index. Calling it "add" would overlap with the collection method.- Parameters:
index
-value
-
-
mul
-
insert
-
swap
-
contains
-
indexOf
-
lastIndexOf
-
removeValue
-
removeIndex
Removes and returns the item at the specified index. -
removeRange
Removes the items between the specified indices, inclusive. -
removeAll
Removes from this array all of elements contained in the specified array.- Returns:
- true if this array was modified.
-
pop
Removes and returns the last item. -
peek
Returns the last item. -
first
Returns the first item. -
clear
-
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
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
-
resize
-
asInts
-
sort
-
reverse
-
truncate
Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken. -
toArray
-
hashCode
-
equals
-
toString
-
toString
-
with
- See Also:
ShortVLA(short[])
-