Class AlgorithmBrainExtractor.UnorderedSetInt

  • Enclosing class:
    AlgorithmBrainExtractor

    private class AlgorithmBrainExtractor.UnorderedSetInt
    extends java.lang.Object
    An unordered set of 'int' stored in an array. The class is used to store adjacency information for the triangles in the mesh representing the brain surface. The reason for using an array is to minimize reallocations during dynamic changes to a mesh. When an item is deleted from the set, the last element in the array is moved into that location. The sets for which this class is used are typically small, so the costs for searching the unordered items are not a factor.

    The class has a static value DEFAULT_GROW that is used to increase the number of elements when a reallocation must occur. The new storage size is the current maximum quantity plus the growth value.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int DEFAULT_GROW
      The default growth value for reallocations of the array representing the set.
      protected int[] m_aiElement
      The array storage for the set.
      protected int m_iGrow
      On a reallocation, the old maximum quantity is incremented by this value.
      protected int m_iMaxQuantity
      The maximum number of elements in the array.
      protected int m_iNewIndex
      Support for remove and removeAt.
      protected int m_iOldIndex
      Support for remove and removeAt.
      protected int m_iQuantity
      The number of valid elements in the array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int append​(int iElement)
      Append an element to the end of the storage array.
      void compactify()
      Use exactly the amount of array storage for the current elements in the set.
      void copy​(AlgorithmBrainExtractor.UnorderedSetInt kSet)
      Make a deep copy of the input set.
      boolean exists​(int iElement)
      Search the set to see if the input element currently exists.
      int get​(int i)
      Retrieve the element in the array location i.
      int getGrow()
      The growth value for reallocations.
      int getMaxQuantity()
      The maximum quantity of elements in the set.
      int getNewIndex()
      On a call to remove or removeAt, the last element in the array is potentially moved to the array location vacated by the removed element.
      int getOldIndex()
      On a call to remove or removeAt, the last element in the array is moved to the array location vacated by the removed element.
      int getQuantity()
      The current number of valid elements in the array.
      boolean insert​(int iElement)
      Insert an element into the set.
      boolean remove​(int iElement)
      Remove the specified element from the set.
      boolean removeAt​(int i)
      Remove the element from the set in the specified location.
      void reset()
      Reset the unordered set to its initial state.
      void reset​(int iMaxQuantity, int iGrow)
      Reset the unordered set to the specified state.
      void set​(int i, int iElement)
      Assign the specified element to array location i.
      • Methods inherited from class java.lang.Object

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

      • m_aiElement

        protected int[] m_aiElement
        The array storage for the set.
      • m_iGrow

        protected int m_iGrow
        On a reallocation, the old maximum quantity is incremented by this value.
      • m_iMaxQuantity

        protected int m_iMaxQuantity
        The maximum number of elements in the array. It is always the case that m_iQuantity
        • m_iOldIndex

          protected int m_iOldIndex
          Support for remove and removeAt.
        • m_iNewIndex

          protected int m_iNewIndex
          Support for remove and removeAt.
        • m_iQuantity

          protected int m_iQuantity
          The number of valid elements in the array. The valid indices are 0
          • DEFAULT_GROW

            private final int DEFAULT_GROW
            The default growth value for reallocations of the array representing the set. The application can change this to whatever is appropriate for its purposes.
            See Also:
            Constant Field Values
          • Constructor Detail

            • UnorderedSetInt

              public UnorderedSetInt()
              Construct an empty unordered set. The initial maximum quantity and growth values are DEFAULT_GROW. When
            • UnorderedSetInt

              public UnorderedSetInt​(AlgorithmBrainExtractor.UnorderedSetInt kSet)
              Create an unordered set that is a deep copy of the input set.
              Parameters:
              kSet - The input set to copy.
            • UnorderedSetInt

              public UnorderedSetInt​(int iMaxQuantity,
                                     int iGrow)
              Construct an empty unordered set with the specified maximum quantity and growth values.
              Parameters:
              iMaxQuantity - The initial number of elements in the array. If the value is nonpositive, the initial number is DEFAULT_GROW.
              iGrow - The growth amount for a reallocation. If a reallocation occurs, the new number of elements is the current maximum quantity plus the growth value. If the input value is nonpositive, the growth is set to DEFAULT_GROW.
          • Method Detail

            • append

              public int append​(int iElement)
              Append an element to the end of the storage array.
              Parameters:
              iElement - The element to append.
              Returns:
              The array location that contains the newly appended element. A side effect of this call is reallocation of the storage array, if necessary.
            • compactify

              public void compactify()
              Use exactly the amount of array storage for the current elements in the set. After the call, getQuantity() and getMaximumQuantity() return the same value. This call does cause a reallocation.
            • exists

              public final boolean exists​(int iElement)
              Search the set to see if the input element currently exists.
              Parameters:
              iElement - The element to search for.
              Returns:
              The value is true if and only if the element is found in the set.
            • get

              public final int get​(int i)
              Retrieve the element in the array location i. It is necessary that 0
              Parameters:
              i - The array location whose element is to be retrieved.
              Returns:
              The element in array location i.
              • getGrow

                public final int getGrow()
                The growth value for reallocations. If a reallocation must occur, the new maximum quantity is the current maximum quantity plus the growth amount.
                Returns:
                The growth value.
              • getMaxQuantity

                public final int getMaxQuantity()
                The maximum quantity of elements in the set. Not all elements are necessarily used. The used quantity is provided by getQuantity().
                Returns:
                The maximum quantity of elements in the set.
              • getNewIndex

                public final int getNewIndex()
                On a call to remove or removeAt, the last element in the array is potentially moved to the array location vacated by the removed element. The new location of the last element is retrived by this function. However, if the last element is the one that was removed, this function returns -1. If you need the value, you must call this function before the next call to remove or removeAt.
                Returns:
                The new location of the last element that was moved.
              • getOldIndex

                public final int getOldIndex()
                On a call to remove or removeAt, the last element in the array is moved to the array location vacated by the removed element. The old location of the last element is retrived by this function. If you need the value, you must call this function before the next call to remove or removeAt.
                Returns:
                The old location of the last element that was moved.
              • getQuantity

                public final int getQuantity()
                The current number of valid elements in the array. This number is less than or equal to the maximum quantity. The elements with indices 0 through getQuantity()-1 are the valid ones.
                Returns:
                The current number of valid elements.
              • insert

                public boolean insert​(int iElement)
                Insert an element into the set.
                Parameters:
                iElement - The element to insert.
                Returns:
                The value is true if and only if the element is inserted. The input element is not inserted if it already exists in the set. A side effect of this call is reallocation of the storage array, if necessary.
              • remove

                public boolean remove​(int iElement)
                Remove the specified element from the set.
                Parameters:
                iElement - The element to remove.
                Returns:
                The value is true if and only if the element existed and was removed. The last element is potentially moved into the slot vacated by the specified element. If needed, the old and new locations of the last element can be retrieved by calls to getOldIndex() and getNewIndex(). If the last element was the one removed, getNewIndex() returns -1.
              • removeAt

                public boolean removeAt​(int i)
                Remove the element from the set in the specified location.
                Parameters:
                i - The array location whose element is to be removed.
                Returns:
                The value is true if and only if the input location is within the valid index range 0
              • reset

                public void reset()
                Reset the unordered set to its initial state. The old array is deleted. The new array has a maximum quantity of DEFAULT_GROW and the growth value is DEFAULT_GROW.
              • reset

                public void reset​(int iMaxQuantity,
                                  int iGrow)
                Reset the unordered set to the specified state. The old array is deleted. The new array has a maximum quantity and growth value as specified by the inputs.
                Parameters:
                iMaxQuantity - The new maximum quantity for the array.
                iGrow - The new growth value.
              • set

                public final void set​(int i,
                                      int iElement)
                Assign the specified element to array location i. It is necessary that 0
                Parameters:
                i - The array location to assign to.
                iElement - The element to assign to array location i.