Interface ISet

    • Method Detail

      • iterator

        ISetIterator iterator()
        Use the following loop to iterate over this set without autoboxing. // more readable but with autoboxing for(int value:set){ ... } // more verbose but without autoboxing ISetIterator iter = set.primitiveIterator(); while(iter.hasNext()){ int k = iter.next(); ... } Do not use this iterator to make nested loops over ISet (prefer newIterator())
        Specified by:
        iterator in interface Iterable<Integer>
        Returns:
        the default iterator (singleton) of this set
      • newIterator

        ISetIterator newIterator()
        Creates a new iterator object, for nested loops only.
        Returns:
        a new iterator for this set
      • add

        boolean add​(int element)
        Add element to the set
        Parameters:
        element - element to add
        Returns:
        true iff element was not in the set and has been added
      • remove

        boolean remove​(int element)
        Remove the first occurrence of element from the set
        Parameters:
        element - element to add
        Returns:
        true iff element was in the set and has been removed
      • contains

        boolean contains​(int element)
        Test the existence of element in the set
        Parameters:
        element - element to add
        Returns:
        true iff the set contains element
      • isEmpty

        default boolean isEmpty()
        Returns:
        true iff the set is empty
      • size

        int size()
        Returns:
        the number of elements in the set
      • clear

        void clear()
        Remove all elements from the set
      • min

        int min()
        Returns:
        the smallest element in the set throws an exception if the set is empty Time complexity is linear for BIPARTITESET and LINKED_LIST (constant time otherwise)
      • max

        int max()
        Returns:
        the largest element in the set throws an exception if the set is empty Time complexity is linear for BIPARTITESET and LINKED_LIST (constant time otherwise)
      • getSetType

        SetType getSetType()
        Returns:
        the implementation type of this set
      • registerObserver

        void registerObserver​(ISet set,
                              int idx)
        Register an observer to this set. Observers are dynamic set data structures whose value depends on observed sets. This method must be called by observers' constructors.
        Parameters:
        set - The observer to register
        idx - This index of this set in the observing set.
      • notifyElementAdded

        default void notifyElementAdded​(int element,
                                        int idx)
        Operations to perform when an observed set has an element added.
        Parameters:
        element - the element added to the observed set.
        idx - the index of the observed set.
      • notifyElementRemoved

        default void notifyElementRemoved​(int element,
                                          int idx)
        Operations to perform when an observed set has an element removed.
        Parameters:
        element - the element removed to the observed set.
        idx - the index of the observed set.
      • notifyCleared

        default void notifyCleared​(int idx)
        Operations to perform when an observed set is cleared
        Parameters:
        idx - the index of the observed set.
      • toArray

        default int[] toArray()
        Copies the set in an array if integers
        Returns:
        an array containing every integer of the set