Class SortedIntSet


  • public class SortedIntSet
    extends java.lang.Object
    A set of integers, maintained as a sorted array. Note that the actual array used to implement this class grows in larger increments, so it is efficient to use this class even when doing lots of insertions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private IntVector vector  
    • Constructor Summary

      Constructors 
      Constructor Description
      SortedIntSet()
      Default constructor.
      SortedIntSet​(int[] array)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int ele)
      Add element to set.
      boolean contains​(int ele)  
      int find​(int ele)
      Find position of ele in set.
      int get​(int pos)
      Get element at position.
      int[] getArray()  
      boolean remove​(int ele)
      Remove element from set.
      void removeAll()  
      int size()
      Number of elements in set.
      int[] toArray()  
      void union​(SortedIntSet set)  
      • Methods inherited from class java.lang.Object

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

      • SortedIntSet

        public SortedIntSet()
        Default constructor.
      • SortedIntSet

        public SortedIntSet​(int[] array)
    • Method Detail

      • find

        public int find​(int ele)
        Find position of ele in set.
        Parameters:
        ele - The element we're looking for.
        Returns:
        The position, if found; a negative value, else. See IntArrayUtils.binarySearch().
      • contains

        public boolean contains​(int ele)
        Parameters:
        ele - -
        Returns:
        true iff ele is contained in the set.
      • add

        public boolean add​(int ele)
        Add element to set.
        Parameters:
        ele - -
        Returns:
        true iff ele was not already contained in the set.
      • remove

        public boolean remove​(int ele)
        Remove element from set.
        Parameters:
        ele - -
        Returns:
        true iff ele was actually contained in the set.
      • size

        public int size()
        Number of elements in set.
        Returns:
        Current number of elements in set.
      • get

        public int get​(int pos)
        Get element at position.
        Parameters:
        pos - Get element at this position.
        Returns:
        The element at this position.
      • removeAll

        public void removeAll()
      • toArray

        public int[] toArray()
      • getArray

        public int[] getArray()