Package gov.nih.mipav.model.structures
Class IntVector
java.lang.Object
gov.nih.mipav.model.structures.IntVector
Integer Vector is very similar to the Vector class except that it is designed specifically to store integers. The
Vector class could have been used but because this class is specifically used to store integers it is significantly
faster. It was primarily used for the Watershed algorithm but is general in nature. Remember to choose your initial
capacity and chunk size wisely to reduce the time spent reallocating the int vector buffer.
- Version:
- 0.1 March 20, 1998
- Author:
- Matthew McAuliffe. Ph.D.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe initial number of elements to have space for in the vector.private intThe number of elements to add to the total number allocated when more space is needed to store the data in the vector.private intThe number of valid data elements added to the vector.private intThe index of the first valid data element in the vector.private int[]The vector data.private int[]The temporary array used when increasing the storage space of the vector.private intThe index of the last valid data element in the vector. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddElement(int x) Pushes a new value onto the array.copy()Clones the integer vector.Copies this array into the array passed in as an argument.voidfinalize()Cleans the memory used by the int vector.final intGets the first element of array without removing it.final intgetElementAt(int index) Gets a value from the array.final booleanisEmpty()Returns flag indicating if the array is empty.final intGets last element of array without removing it.intlength()Length of the array (ie - how many data points are stored).final intPops first value off the FIFO array.final intPops last value off the FILO array.final voidpush(int x) Pushes a new value onto the array.voidRemoves all elements of the array.voidremoveElementAt(int i) Removes element at index.final voidRemoves last element is array.voidsetCapacity(int cap) Sets the capacity of the array.voidsetChunk(int chunk) Sets the chunk size when adding memory to the array.final intGets the smallest in value element of array without removing it.
-
Field Details
-
capacity
private int capacityThe initial number of elements to have space for in the vector. -
chunk
private int chunkThe number of elements to add to the total number allocated when more space is needed to store the data in the vector. -
currentLength
private int currentLengthThe number of valid data elements added to the vector. -
firstPtr
private int firstPtrThe index of the first valid data element in the vector. -
intBuffer
private int[] intBufferThe vector data. -
intTemp
private int[] intTempThe temporary array used when increasing the storage space of the vector. -
ptr
private int ptrThe index of the last valid data element in the vector.
-
-
Constructor Details
-
IntVector
public IntVector()Create an list or stack of ints. -
IntVector
public IntVector(int capacity) Create an list or stack of ints.- Parameters:
capacity- initial capacity of the array
-
IntVector
public IntVector(int capacity, int chunk) Create an list or stack of ints.- Parameters:
capacity- initial capacity of the arraychunk- the size of memory to add when the array needs expanding
-
-
Method Details
-
addElement
public final void addElement(int x) Pushes a new value onto the array. Checks to make sure array has the capacity to store the new value. If not, this allocates the more memory by the size specified in the variable chunk.- Parameters:
x- value to be pushed onto the array
-
copy
Clones the integer vector.- Returns:
- new copy of the vector
-
copy
Copies this array into the array passed in as an argument.- Parameters:
pixelsVector- array to hold values from this array- Returns:
- also returns the array
-
finalize
public void finalize()Cleans the memory used by the int vector. -
firstElement
public final int firstElement()Gets the first element of array without removing it.- Returns:
- first element of array
-
getElementAt
public final int getElementAt(int index) Gets a value from the array.- Parameters:
index- index of value to be returned- Returns:
- element at the specified index. If index is out of range then Integer.MIN_VALUE is returned
-
isEmpty
public final boolean isEmpty()Returns flag indicating if the array is empty.- Returns:
- flag indicating emptiness (true = empty and false = not empty)
-
lastElement
public final int lastElement()Gets last element of array without removing it.- Returns:
- last element of array
-
length
public int length()Length of the array (ie - how many data points are stored).- Returns:
- number of data points and not total size of array
-
popFirstIn
public final int popFirstIn()Pops first value off the FIFO array.- Returns:
- returns value of the top of the array. If the array is empty it returns -1.
-
popLastIn
public final int popLastIn()Pops last value off the FILO array.- Returns:
- returns value of the top of the array. If the array is empty it returns -1.
-
push
public final void push(int x) Pushes a new value onto the array. Checks to make sure array has the capacity to store the new value. If not, this allocates the more memory by the size specified in the variable chunk.- Parameters:
x- value to be pushed onto the array
-
removeAllElements
public void removeAllElements()Removes all elements of the array. -
removeElementAt
public void removeElementAt(int i) Removes element at index. Slow method - this is not a linked list.- Parameters:
i- index of value to be removed
-
removeLastElement
public final void removeLastElement()Removes last element is array. -
setCapacity
public void setCapacity(int cap) Sets the capacity of the array.- Parameters:
cap- capacity of the array
-
setChunk
public void setChunk(int chunk) Sets the chunk size when adding memory to the array.- Parameters:
chunk- the size of memory to add when the array needs expanding
-
smallestElement
public final int smallestElement()Gets the smallest in value element of array without removing it.- Returns:
- smallest element of array
-