Class AlgorithmObjectExtractor.UnorderedSetInt

java.lang.Object
gov.nih.mipav.model.algorithms.AlgorithmObjectExtractor.UnorderedSetInt
Enclosing class:
AlgorithmObjectExtractor

private class AlgorithmObjectExtractor.UnorderedSetInt extends 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 object 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
    The default growth value for reallocations of the array representing the set.
    protected int[]
    The array storage for the set.
    protected int
    On a reallocation, the old maximum quantity is incremented by this value.
    protected int
    The maximum number of elements in the array.
    protected int
    Support for remove and removeAt.
    protected int
    Support for remove and removeAt.
    protected int
    The number of valid elements in the array.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct an empty unordered set.
    UnorderedSetInt(int iMaxQuantity, int iGrow)
    Construct an empty unordered set with the specified maximum quantity and growth values.
    Create an unordered set that is a deep copy of the input set.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    append(int iElement)
    Append an element to the end of the storage array.
    void
    Use exactly the amount of array storage for the current elements in the set.
    void
    Make a deep copy of the input set.
    boolean
    exists(int iElement)
    Search the set to see if the input element currently exists.
    final int
    get(int i)
    Retrieve the element in the array location i.
    final int
    The growth value for reallocations.
    final int
    The maximum quantity of elements in the set.
    final int
    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.
    final int
    On a call to remove or removeAt, the last element in the array is moved to the array location vacated by the removed element.
    final int
    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 the unordered set to its initial state.
    void
    reset(int iMaxQuantity, int iGrow)
    Reset the unordered set to the specified state.
    final 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 Details

    • 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 invalid input: '<'= m_iMaxQuantity.
    • 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 invalid input: '<'= i invalid input: '<' m_iQuantity.
    • DEFAULT_GROW

      private 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.
  • Constructor Details

    • UnorderedSetInt

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

      public UnorderedSetInt(AlgorithmObjectExtractor.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 Details

    • 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.
    • copy

      Make a deep copy of the input set.
      Parameters:
      kSet - The set to make a deep copy of.
    • exists

      public 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 invalid input: '<'= i invalid input: '<' getQuantity() in order to read valid elements.
      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 invalid input: '<'= i invalid input: '<' getQuantity(). 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.
    • 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 invalid input: '<'= i invalid input: '<' getMaxQuantity().
      Parameters:
      i - The array location to assign to.
      iElement - The element to assign to array location i.