Class Set_CstInterval

  • All Implemented Interfaces:
    Iterable<Integer>, ISet

    public class Set_CstInterval
    extends Object
    implements ISet
    Constant Interval set of the form [min, max] BEWARE: Cannot add/remove elements
    Author:
    Jean-Guillaume Fages
    • Constructor Detail

      • Set_CstInterval

        public Set_CstInterval​(int min,
                               int max)
        Creates a constant set of integers encoded as an interval [min, max]
        Parameters:
        min - lowest value in the set
        max - highest value in the 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
      • getSetType

        public SetType getSetType()
        Specified by:
        getSetType in interface ISet
        Returns:
        the implementation type of this set
      • 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)
      • 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