Class IntSet

  • All Implemented Interfaces:
    PositiveIntSet

    public class IntSet
    extends java.lang.Object
    implements PositiveIntSet
    This class implements a set of integers. It does not implement the Set interface for performance reasons, though methods with the same name are equivalent. This does not implement shorts + offset, like the IntHashSet does because by the time that might be of interest, we would switch to IntHashSet to get ~O(1) operations including contains.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  IntSet.IntSetIterator  
    • Constructor Summary

      Constructors 
      Constructor Description
      IntSet()
      Creates a new instance of this set.
      IntSet​(int capacity)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int element)
      Adds the specified int to this set.
      void bulkAddTo​(IntVector v)
      add all elements in this set to the IntVector v as a bulk operation
      void clear()
      remove all members of the set
      boolean contains​(int element)
      Tests if this set contains the specified element.
      boolean equals​(java.lang.Object o)
      Tests if two sets are equal.
      int find​(int element)  
      int get​(int n)
      Used for FsBagIndex, and internally to compute most positive/neg
      int hashCode()  
      int indexOf​(int element)  
      boolean isValid​(int position)
      For FSBagIndex low level iterator use
      IntSet.IntSetIterator iterator()  
      int moveToFirst()
      For FSBagIndex low level iterator use
      int moveToLast()
      For FSBagIndex low level iterator use
      int moveToNext​(int position)
      For FSBagIndex low level iterator use
      int moveToPrevious​(int position)
      For FSBagIndex low level iterator use
      boolean remove​(int key)  
      void removeElementAt​(int n)
      Removes the n-th element in this set.
      int size()  
      int[] toIntArray()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • IntSet

        public IntSet()
        Creates a new instance of this set.
      • IntSet

        public IntSet​(int capacity)
        Parameters:
        capacity - allocate enough space to hold at least this before expanding
    • Method Detail

      • add

        public boolean add​(int element)
        Adds the specified int to this set.
        Specified by:
        add in interface PositiveIntSet
        Parameters:
        element - the integer to be added.
        Returns:
        true if this set did not already contain this element, false otherwise.
      • contains

        public boolean contains​(int element)
        Tests if this set contains the specified element.
        Specified by:
        contains in interface PositiveIntSet
        Parameters:
        element - the element to be tested.
        Returns:
        true if the element is contained in this set, false otherwise.
      • find

        public int find​(int element)
        Specified by:
        find in interface PositiveIntSet
        Parameters:
        element - an item which may be in the set
        Returns:
        -1 if the item is not in the set, or a position value that can be used with iterators to start at that item.
      • size

        public int size()
        Specified by:
        size in interface PositiveIntSet
        Returns:
        the size of this set.
      • get

        public int get​(int n)
        Used for FsBagIndex, and internally to compute most positive/neg
        Specified by:
        get in interface PositiveIntSet
        Parameters:
        n - the position
        Returns:
        the value at that position
      • removeElementAt

        public void removeElementAt​(int n)
        Removes the n-th element in this set.
        Parameters:
        n - -
      • equals

        public boolean equals​(java.lang.Object o)
        Tests if two sets are equal. This is the case if the two sets are of the same size, and every element in one set in contained in the other set.
        Note that in order to increase performance, before the sets are actually compared the way described above, the sums of the elements in both sets are calculated, ignoring possible int overflows. If the sums are not equal, the two sets cannot be equal. In case the sums are equal, the two sets are compared element by element.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the set to be tested for equality with this set.
        Returns:
        true if the sets are equal, false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • indexOf

        public int indexOf​(int element)
      • remove

        public boolean remove​(int key)
        Specified by:
        remove in interface PositiveIntSet
        Parameters:
        key - -
        Returns:
        true if the set had this element before the remove
      • moveToFirst

        public int moveToFirst()
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToFirst in interface PositiveIntSet
        Returns:
        the position of the first element, or -1;
      • moveToLast

        public int moveToLast()
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToLast in interface PositiveIntSet
        Returns:
        the position of the last element, or -1;
      • moveToNext

        public int moveToNext​(int position)
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToNext in interface PositiveIntSet
        Parameters:
        position - -
        Returns:
        the position of the next element, or -1;
      • moveToPrevious

        public int moveToPrevious​(int position)
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        moveToPrevious in interface PositiveIntSet
        Parameters:
        position - -
        Returns:
        the position of the next element, or -1;
      • isValid

        public boolean isValid​(int position)
        Description copied from interface: PositiveIntSet
        For FSBagIndex low level iterator use
        Specified by:
        isValid in interface PositiveIntSet
        Parameters:
        position - -
        Returns:
        true if the position is between the first and last element inclusive.
      • bulkAddTo

        public void bulkAddTo​(IntVector v)
        Description copied from interface: PositiveIntSet
        add all elements in this set to the IntVector v as a bulk operation
        Specified by:
        bulkAddTo in interface PositiveIntSet
        Parameters:
        v - - to be added to
      • toIntArray

        public int[] toIntArray()
        Specified by:
        toIntArray in interface PositiveIntSet
        Returns:
        the set as an arbitrarily ordered int array
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object