public class IntVLA
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
Constructor and Description |
---|
IntVLA()
Creates an ordered array with a capacity of 16.
|
IntVLA(int capacity)
Creates an ordered array with the specified capacity.
|
IntVLA(int[] array)
Creates a new ordered array containing the elements in the specified array.
|
IntVLA(int[] array,
int startIndex,
int count)
Creates a new array containing the elements in the specified array.
|
IntVLA(IntVLA array)
Creates a new array containing the elements in the specific array.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int value) |
void |
addAll(int... array) |
void |
addAll(int[] array,
int offset,
int length) |
void |
addAll(IntSet set) |
void |
addAll(IntVLA array) |
void |
addAll(IntVLA array,
int offset,
int length) |
void |
addFractionRange(int start,
int end,
int fraction) |
void |
addRange(int start,
int end) |
void |
clear() |
java.lang.Object |
clone() |
boolean |
contains(int value) |
IntVLA |
copy() |
static IntVLA |
deserializeFromString(java.lang.String data) |
int[] |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to accommodate the specified number of additional items.
|
boolean |
equals(java.lang.Object object) |
int |
first()
Returns the first item.
|
int |
get(int index) |
int |
getRandomElement(IRNG random) |
long |
hash64()
Hashes this IntVLA using
CrossHash.Water , getting a 64-bit result. |
int |
hashCode()
Hashes this IntVLA using
CrossHash.Water , getting a 32-bit result. |
int |
hashHive()
Gets a mid-quality hash code using the 32-bit part of the Hive algorithm; this uses only int math and so is an
excellent option on GWT.
|
int |
hashWisp()
Gets a low-to-mid-quality hash code quickly using the Wisp algorithm; you should prefer
hashHive() in
code that needs to run on GWT, since that method avoids the long math that is expensive on GWT. |
void |
incr(int index,
int value)
Adds value to the item in the IntVLA at index.
|
int |
indexOf(int value)
Tries to find the first occurrence of
value in this IntVLA, and returns the index that value appears at
if it is present, or -1 if it is not present. |
void |
insert(int index,
int value) |
boolean |
isEmpty() |
int |
lastIndexOf(int value) |
int |
moveToFirst(int value)
Moves the specified value to the first index and returns its previous index.
|
int |
moveToLast(int value)
Moves the specified value to the last index and returns its previous index.
|
void |
mul(int index,
int value) |
int |
peek()
Returns the last item.
|
int |
pop()
Removes and returns the last item.
|
boolean |
removeAll(IntVLA array)
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.
|
int |
removeValue(int value)
Removes the first occurrence of the requested value, and returns the index it was removed at (-1 if not found)
|
IntVLA |
reorder(int... ordering)
Given an array or varargs of replacement indices for the values of this IntVLA, reorders this so the first item
in the returned version is the same as
get(ordering[0]) (with some care taken for negative or too-large
indices), the second item in the returned version is the same as get(ordering[1]) , etc. |
protected int[] |
resize(int newSize) |
void |
reverse() |
void |
set(int index,
int value) |
int[] |
setSize(int newSize)
Sets the array size, leaving any values beyond the current size undefined.
|
int[] |
shrink()
Reduces the size of the backing array to the size of the actual items.
|
IntVLA |
shuffle(IRNG random)
Shuffles this IntVLA in place using the given IRNG.
|
void |
sort() |
void |
swap(int first,
int second) |
int[] |
toArray() |
java.lang.String |
toString() |
java.lang.String |
toString(java.lang.String separator) |
void |
truncate(int newSize)
Reduces the size of the array to the specified size.
|
static IntVLA |
with(int... array) |
public IntVLA()
public IntVLA(int capacity)
public IntVLA(IntVLA array)
public IntVLA(int[] array)
public IntVLA(int[] array, int startIndex, int count)
array
- the int array to copy fromstartIndex
- the first index in array to copy fromcount
- the number of ints to copy from array into this IntVLApublic void add(int value)
public void addAll(IntVLA array)
public void addAll(IntVLA array, int offset, int length)
public void addAll(IntSet set)
public void addAll(int... array)
public void addAll(int[] array, int offset, int length)
public void addRange(int start, int end)
public void addFractionRange(int start, int end, int fraction)
public int get(int index)
public void set(int index, int value)
public void incr(int index, int value)
index
- the index of the item to add tovalue
- how much to add to the item at index (this may be negative, positive, or 0)public void mul(int index, int value)
public void insert(int index, int value)
public void swap(int first, int second)
public IntVLA reorder(int... ordering)
get(ordering[0])
(with some care taken for negative or too-large
indices), the second item in the returned version is the same as get(ordering[1])
, etc.
ordering[ordering.length - 1]
. If ordering is smaller than this IntVLA, only the indices up to the
length of ordering will be modified. If ordering is larger than this IntVLA, only as many indices will be
affected as this IntVLA's size, and reversed distances are measured from the end of this IntVLA instead of the
end of ordering. Duplicate values in ordering will produce duplicate values in the returned IntVLA.
ordering
- an array or varargs of int indices, where the nth item in ordering changes the nth item in this
IntVLA to have the value currently in this IntVLA at the index specified by the value in orderingpublic boolean contains(int value)
public int indexOf(int value)
value
in this IntVLA, and returns the index that value appears at
if it is present, or -1 if it is not present.value
- a value to search for in thispublic int lastIndexOf(int value)
public int removeValue(int value)
value
- a value in this IntVLA to removepublic int removeIndex(int index)
public void removeRange(int start, int end)
public boolean removeAll(IntVLA array)
public int moveToFirst(int value)
value
- an int value that should already be in this IntVLApublic int moveToLast(int value)
value
- an int value that should already be in this IntVLApublic int pop()
public int peek()
public int first()
public void clear()
public int[] shrink()
items
public int[] ensureCapacity(int additionalCapacity)
items
public int[] setSize(int newSize)
items
protected int[] resize(int newSize)
public void sort()
public void reverse()
public void truncate(int newSize)
public int getRandomElement(IRNG random)
public IntVLA shuffle(IRNG random)
random
- an IRNG, such as an RNG, used to generate the shuffled orderpublic int[] toArray()
public IntVLA copy()
public java.lang.Object clone()
clone
in class java.lang.Object
public int hashCode()
CrossHash.Water
, getting a 32-bit result. The same algorithm is used by
hash64()
, just with different constants and a different final step here.hashCode
in class java.lang.Object
public int hashWisp()
hashHive()
in
code that needs to run on GWT, since that method avoids the long math that is expensive on GWT. You are fine
using hashCode()
when you need quality and low collison rates; Wisp tends to collide too often on some
data sets.hashCode()
public int hashHive()
hashCode()
, which uses
a higher-quality and sometimes faster algorithm, but only has that speed advantage on 64-bit JVMs.
hash64()
uses almost exactly the same algorithm as hashCode(), both in CrossHash.Water
.public long hash64()
CrossHash.Water
, getting a 64-bit result. The same algorithm is used by
hashCode()
, just with different constants and a different final step here.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String separator)
public static IntVLA deserializeFromString(java.lang.String data)
public static IntVLA with(int... array)
IntVLA(int[])
public boolean isEmpty()
Copyright © Eben Howard 2012–2022. All rights reserved.