Class IncreasingSubsetIterator<T>

  • Type Parameters:
    T - The element class which is iterated.
    All Implemented Interfaces:
    java.util.Iterator<java.util.Set<T>>

    public class IncreasingSubsetIterator<T>
    extends SubsetIterator<T>
    Iterates over all subsets of a given set. This iterator first returns the empty set, then all 1-element subsets, then all 2-element subsets,...
    Author:
    Matthias Thimm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int currentSize
      The current size of the subsets generated.
      private boolean hasNext
      For hasNext().
      private int[] indices
      The indices of the generated subsets.
      private java.util.List<T> set
      The actual set in a list.
    • Constructor Summary

      Constructors 
      Constructor Description
      IncreasingSubsetIterator​(java.util.Set<T> set)
      Creates a new subset iterator for the given set.
    • Method Summary

      Modifier and Type Method Description
      boolean hasNext()  
      private void increment()
      Increments the indices.
      private int increment​(int lvl)
      Increments the indices.
      java.util.Set<T> next()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • set

        private java.util.List<T> set
        The actual set in a list.
      • indices

        private int[] indices
        The indices of the generated subsets.
      • currentSize

        private int currentSize
        The current size of the subsets generated.
      • hasNext

        private boolean hasNext
        For hasNext().
    • Constructor Detail

      • IncreasingSubsetIterator

        public IncreasingSubsetIterator​(java.util.Set<T> set)
        Creates a new subset iterator for the given set.
        Parameters:
        set - some set.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T>
        Specified by:
        hasNext in class SubsetIterator<T>
      • next

        public java.util.Set<T> next()
        Specified by:
        next in interface java.util.Iterator<T>
        Specified by:
        next in class SubsetIterator<T>
      • increment

        private void increment()
        Increments the indices.
      • increment

        private int increment​(int lvl)
        Increments the indices.
        Parameters:
        lvl - the level
        Returns:
        the new index