Module org.maxicp

Class StateSparseSet

java.lang.Object
org.maxicp.state.datastructures.StateSparseSet

public class StateSparseSet extends Object
Set implemented using a sparse-set data structure that can be saved and restored through the StateManager.saveState() / StateManager.restoreState() methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StateSparseSet(StateManager sm, int n, int ofs)
    Creates a set containing the elements {ofs,ofs+1,...,ofs+n-1}.
    Creates a set containing the elements of values.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(int val)
    Checks if a value is in the set.
    int
    fillArray(int[] dest)
    Sets the first values of dest to the ones present in the set.
    int
    fillArrayWithFilter(int[] dest, Predicate<Integer> filterPredicate)
    Sets the first values of dest to the ones present in the set that also satisfy the given filter predicate
    int
    fillDeltaArray(int oldMin, int oldMax, int oldSize, int[] arr)
     
    int
    fillExcluded(int[] dest)
    Sets the first values of dest to the ones present in the set.
    int
    The initial maximum value of the sparse-set (at its creation)
    int
    The initial minimum value of the sparse-set (at its creation)
    int
    The initial size of the sparse-set (at its creation)
    boolean
    Checks if the set is empty
    int
    max()
    Returns the maximum value in the set.
    int
    min()
    Returns the minimum value in the set.
    boolean
    remove(int val)
    Removes the given value from the set.
    int
    Removes the value for which a given predicate is true
    void
    removeAbove(int value)
    Remove all the values larger than the given value from the set
    void
    Removes all the values in the set.
    void
    removeAllBut(int v)
    Removes all the element from the set except the given value.
    void
    removeBelow(int value)
    Remove all the values less than the given value from the set
    int
    Returns the size of the set.
    int[]
    Returns an array with the values present in the set.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • StateSparseSet

      public StateSparseSet(StateManager sm, int n, int ofs)
      Creates a set containing the elements {ofs,ofs+1,...,ofs+n-1}.
      Parameters:
      sm - the state manager that will save and restore the set when StateManager.saveState() / StateManager.restoreState() mehtods are called
      n - the number of elements in the set
      ofs - the minimum value in the set containing {ofs,ofs+1,...,ofs+n-1}
    • StateSparseSet

      public StateSparseSet(StateManager sm, Set<Integer> values)
      Creates a set containing the elements of values.
      Parameters:
      sm - the state manager that will save and restore the set when StateManager.saveState() / StateManager.restoreState() mehtods are called
      values - the elements to initialize the set with
  • Method Details

    • initMin

      public int initMin()
      The initial minimum value of the sparse-set (at its creation)
      Returns:
      the initial minimum value of the sparse-set
    • initMax

      public int initMax()
      The initial maximum value of the sparse-set (at its creation)
      Returns:
      the initial maximum value of the sparse-set
    • initSize

      public int initSize()
      The initial size of the sparse-set (at its creation)
      Returns:
    • toArray

      public int[] toArray()
      Returns an array with the values present in the set.
      Returns:
      an array representation of the values present in the set
    • fillArray

      public int fillArray(int[] dest)
      Sets the first values of dest to the ones present in the set.
      Parameters:
      dest - , an array large enough dest.length >= size()
      Returns:
      the size of the set
    • fillExcluded

      public int fillExcluded(int[] dest)
      Sets the first values of dest to the ones present in the set.
      Parameters:
      dest - , an array large enough dest.length >= n - size()
      Returns:
      the size of the set
    • fillArrayWithFilter

      public int fillArrayWithFilter(int[] dest, Predicate<Integer> filterPredicate)
      Sets the first values of dest to the ones present in the set that also satisfy the given filter predicate
      Parameters:
      dest - , an array large enough dest.length >= size()
      filterPredicate - the predicate, only elements for which the predicate is true are kept
      Returns:
      the size of the set of elements in the set satisfying hte predicate
    • isEmpty

      public boolean isEmpty()
      Checks if the set is empty
      Returns:
      true if the set is empty
    • size

      public int size()
      Returns the size of the set.
      Returns:
      the size of the set
    • min

      public int min()
      Returns the minimum value in the set.
      Returns:
      the minimum value in the set
    • max

      public int max()
      Returns the maximum value in the set.
      Returns:
      the maximum value in the set
    • remove

      public boolean remove(int val)
      Removes the given value from the set.
      Parameters:
      val - the value to remove.
      Returns:
      true if val was in the set, false otherwise
    • remove

      public int remove(Predicate<Integer> filter)
      Removes the value for which a given predicate is true
      Parameters:
      filter - the predicate, only elements for which the predicate is true are removed
      Returns:
      the size of the set after removal
    • contains

      public boolean contains(int val)
      Checks if a value is in the set.
      Parameters:
      val - the value to check
      Returns:
      true if val is in the set
    • removeAllBut

      public void removeAllBut(int v)
      Removes all the element from the set except the given value.
      Parameters:
      v - is an element in the set
    • removeAll

      public void removeAll()
      Removes all the values in the set.
    • removeBelow

      public void removeBelow(int value)
      Remove all the values less than the given value from the set
      Parameters:
      value - a value such that all the ones smaller are removed
    • removeAbove

      public void removeAbove(int value)
      Remove all the values larger than the given value from the set
      Parameters:
      value - a value such that all the ones greater are removed
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fillDeltaArray

      public int fillDeltaArray(int oldMin, int oldMax, int oldSize, int[] arr)