Module org.maxicp

Class StateLazySparseSet

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

public class StateLazySparseSet extends Object
A sparse-set that lazily switch from a dense interval representation to a sparse-set representation when a hole is created in the interval.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StateLazySparseSet(StateManager sm, int n, int ofs)
    Creates a set containing the elements {ofs,ofs+1,...,ofs+n-1}.
  • 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
    fillDeltaArray(int oldMin, int oldMax, int oldSize, int[] arr)
     
    boolean
     
    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.
    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
     
     

    Methods inherited from class java.lang.Object

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

    • StateLazySparseSet

      public StateLazySparseSet(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}
  • Method Details

    • isEmpty

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

      public int size()
      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
    • 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
    • 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
    • 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
    • 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)