Package com.mckoi.util
Class IntegerVector
java.lang.Object
com.mckoi.util.IntegerVector
- All Implemented Interfaces:
Serializable
Similar to the Vector class, except this can only store integer values.
- Author:
- Tobias Downer
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe Constructors.IntegerVector(int initial_list_size) IntegerVector(IntegerListInterface i_list) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInt(int val) Adds an int to the vector.append(IntegerVector vec) Appends an IntegerVector to the end of the array.voidclear()Clears the object to be re-used.booleancontains(int val) Returns true if the vector contains the given value.voidcrop(int start, int end) Crops the IntegerVector so it only contains values between start (inclusive) and end (exclusive).booleanequals(IntegerVector ivec) Returns true if this vector is equal to the given vector.intgetSize()Returns the size of the vector.intindexOf(int val) Returns the first index of the given row in the array, or -1 if not found.voidinsertIntAt(int val, int pos) Inserts an int at the given position.intintAt(int pos) Returns the Int at the given position.booleanisSorted()Test routine to check vector is sorted.intplaceIntAt(int val, int pos) Places an int at the given position, overwriting anything that was previously there.final voidPerforms a quick sort on the entire vector.final voidquickSort(int min, int max) Performs a quick sort on the array between the min and max bounds.voidremoveInt(int val) Removes the first Int found that matched the specified value.voidremoveIntAt(int pos) Removes an Int from the specified position in the list.voidreverse()Reverses all the list of integers.intsetIntAt(int val, int pos) Sets an int at the given position, overwriting anything that was previously there.intsize()Returns the size of the vector.final intsortedIndexOf(int val) Searches the entire sorted list for the given value and returns the index of it.final intsortedIndexOf(int val, int lower, int higher) This is a very quick search for a value given a sorted array.final intsortedIntCount(int val) Given a sorted list, this will return the count of this value in the list.int[]Converts the vector into an int[] array.toString()Converts the vector into a String.
-
Field Details
-
list
protected int[] listThe int array. -
index
protected int indexThe index of the last value of the array.
-
-
Constructor Details
-
IntegerVector
public IntegerVector()The Constructors. -
IntegerVector
public IntegerVector(int initial_list_size) -
IntegerVector
-
IntegerVector
-
-
Method Details
-
addInt
public void addInt(int val) Adds an int to the vector. -
removeIntAt
public void removeIntAt(int pos) Removes an Int from the specified position in the list. -
removeInt
public void removeInt(int val) Removes the first Int found that matched the specified value. -
crop
public void crop(int start, int end) Crops the IntegerVector so it only contains values between start (inclusive) and end (exclusive). So; crop({ 4, 5, 4, 3, 9, 7 }, 0, 3) would return {4, 5, 4) and, crop({ 4, 5, 4, 3, 9, 7 }, 3, 4) would return {3} -
insertIntAt
public void insertIntAt(int val, int pos) Inserts an int at the given position. -
setIntAt
public int setIntAt(int val, int pos) Sets an int at the given position, overwriting anything that was previously there. It returns the value that was previously at the element. -
placeIntAt
public int placeIntAt(int val, int pos) Places an int at the given position, overwriting anything that was previously there. It returns the value that was previously at the element. If 'pos' points to a place outside the bounds of the list then the list is expanded to include this value. -
append
Appends an IntegerVector to the end of the array. Returns this object. -
intAt
public int intAt(int pos) Returns the Int at the given position. -
indexOf
public int indexOf(int val) Returns the first index of the given row in the array, or -1 if not found. -
contains
public boolean contains(int val) Returns true if the vector contains the given value. -
getSize
public int getSize()Returns the size of the vector. -
size
public int size()Returns the size of the vector. -
toIntArray
public int[] toIntArray()Converts the vector into an int[] array. -
clear
public void clear()Clears the object to be re-used. -
toString
Converts the vector into a String. -
equals
Returns true if this vector is equal to the given vector. -
reverse
public void reverse()Reverses all the list of integers. So integer[0] is swapped with integer[n - 1], integer[1] is swapped with integer[n - 2], etc where n is the size of the vector. -
quickSort
public final void quickSort(int min, int max) Performs a quick sort on the array between the min and max bounds. -
quickSort
public final void quickSort()Performs a quick sort on the entire vector. -
sortedIndexOf
public final int sortedIndexOf(int val, int lower, int higher) This is a very quick search for a value given a sorted array. The search is performed between the lower and higher bounds of the array. If the requested value is not found, it returns the index where the value should be 'inserted' to maintain a sorted list. -
sortedIndexOf
public final int sortedIndexOf(int val) Searches the entire sorted list for the given value and returns the index of it. If the value is not found, it returns the place in the list where the value should be insorted to maintain a sorted list. -
sortedIntCount
public final int sortedIntCount(int val) Given a sorted list, this will return the count of this value in the list. This uses a quick search algorithm so should be quite fast. -
isSorted
public boolean isSorted()Test routine to check vector is sorted.
-