Class Set_Swap2

  • All Implemented Interfaces:
    Iterable<Integer>, ISet

    public class Set_Swap2
    extends Object
    implements ISet
    Set of integers based on BipartiteSet implementation for small sets (arraylist inside) BEWARE : CANNOT BOTH ADD AND REMOVE ELEMENTS DURING SEARCH
    Author:
    : Charles Prud'homme, Jean-Guillaume FAGES
    • Field Detail

      • size

        protected int size
      • values

        protected gnu.trove.list.array.TIntArrayList values
    • Constructor Detail

      • Set_Swap2

        public Set_Swap2()
        Creates an empty bipartite set
    • Method Detail

      • add

        public boolean add​(int element)
        Description copied from interface: ISet
        Add element to the set
        Specified by:
        add in interface ISet
        Parameters:
        element - element to add
        Returns:
        true iff element was not in the set and has been added
      • remove

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

        public boolean contains​(int element)
        Description copied from interface: ISet
        Test the existence of element in the set
        Specified by:
        contains in interface ISet
        Parameters:
        element - element to add
        Returns:
        true iff the set contains element
      • size

        public int size()
        Specified by:
        size in interface ISet
        Returns:
        the number of elements in the set
      • clear

        public void clear()
        Description copied from interface: ISet
        Remove all elements from the set
        Specified by:
        clear in interface ISet
      • min

        public int min()
        Specified by:
        min in interface ISet
        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

        public int max()
        Specified by:
        max in interface ISet
        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

        public SetType getSetType()
        Specified by:
        getSetType in interface ISet
        Returns:
        the implementation type of this set
      • iterator

        public ISetIterator iterator()
        Description copied from interface: ISet
        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 ISet.newIterator())
        Specified by:
        iterator in interface ISet
        Specified by:
        iterator in interface Iterable<Integer>
        Returns:
        the default iterator (singleton) of this set
      • newIterator

        public ISetIterator newIterator()
        Description copied from interface: ISet
        Creates a new iterator object, for nested loops only.
        Specified by:
        newIterator in interface ISet
        Returns:
        a new iterator for this set