Class IntVector


  • public class IntVector
    extends java.lang.Object
    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

      Fields 
      Modifier and Type Field Description
      private int capacity
      The initial number of elements to have space for in the vector.
      private int chunk
      The number of elements to add to the total number allocated when more space is needed to store the data in the vector.
      private int currentLength
      The number of valid data elements added to the vector.
      private int firstPtr
      The index of the first valid data element in the vector.
      private int[] intBuffer
      The vector data.
      private int[] intTemp
      The temporary array used when increasing the storage space of the vector.
      private int ptr
      The index of the last valid data element in the vector.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntVector()
      Create an list or stack of ints.
      IntVector​(int capacity)
      Create an list or stack of ints.
      IntVector​(int capacity, int chunk)
      Create an list or stack of ints.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addElement​(int x)
      Pushes a new value onto the array.
      IntVector copy()
      Clones the integer vector.
      IntVector copy​(IntVector pixelsVector)
      Copies this array into the array passed in as an argument.
      void finalize()
      Cleans the memory used by the int vector.
      int firstElement()
      Gets the first element of array without removing it.
      int getElementAt​(int index)
      Gets a value from the array.
      boolean isEmpty()
      Returns flag indicating if the array is empty.
      int lastElement()
      Gets last element of array without removing it.
      int length()
      Length of the array (ie - how many data points are stored).
      int popFirstIn()
      Pops first value off the FIFO array.
      int popLastIn()
      Pops last value off the FILO array.
      void push​(int x)
      Pushes a new value onto the array.
      void removeAllElements()
      Removes all elements of the array.
      void removeElementAt​(int i)
      Removes element at index.
      void removeLastElement()
      Removes last element is array.
      void setCapacity​(int cap)
      Sets the capacity of the array.
      void setChunk​(int chunk)
      Sets the chunk size when adding memory to the array.
      int smallestElement()
      Gets the smallest in value element of array without removing it.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • capacity

        private int capacity
        The initial number of elements to have space for in the vector.
      • chunk

        private int chunk
        The 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 currentLength
        The number of valid data elements added to the vector.
      • firstPtr

        private int firstPtr
        The index of the first valid data element in the vector.
      • intBuffer

        private int[] intBuffer
        The vector data.
      • intTemp

        private int[] intTemp
        The temporary array used when increasing the storage space of the vector.
      • ptr

        private int ptr
        The index of the last valid data element in the vector.
    • Constructor Detail

      • 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 array
        chunk - the size of memory to add when the array needs expanding
    • Method Detail

      • 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

        public IntVector copy()
        Clones the integer vector.
        Returns:
        new copy of the vector
      • copy

        public IntVector copy​(IntVector pixelsVector)
        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.
        Overrides:
        finalize in class java.lang.Object
      • 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