Class SimpleSolutionManager

java.lang.Object
fr.inria.rules.integraal.query_evaluation.conjunction.backtrack.SimpleSolutionManager
All Implemented Interfaces:
SolutionManager

public final class SimpleSolutionManager extends Object implements SolutionManager

SimpleSolutionManager

Lean, allocation‑friendly implementation of SolutionManager.

Key points:

  • In‑place fusion via mergeInPlace – zero temporary objects on the hot path.
  • For each depth we keep only: the candidate spliterator and truly new variables (those not bound at any shallower level) so rollback work is minimal.
  • A global boundVariables set tracks which variables are already present to compute the fresh set in O(n).
Author:
Guillaume Perution-Kihli
  • Constructor Details

    • SimpleSolutionManager

      public SimpleSolutionManager()
      Creates a solution manager with an empty initial substitution.
    • SimpleSolutionManager

      public SimpleSolutionManager(Substitution prefix)
      Creates a solution manager with the supplied initial substitution.
      Parameters:
      prefix - the substitution that must always remain in the current solution
  • Method Details

    • getCurrentSolution

      public Substitution getCurrentSolution()
      Description copied from interface: SolutionManager
      Returns the substitution that is currently valid at all explored levels.

      Live view: subsequent calls to SolutionManager.next(int) may mutate and/or invalidate the content. Clone it with SolutionManager.copyCurrentSolution() if you need to keep a stable version.

      Specified by:
      getCurrentSolution in interface SolutionManager
      Returns:
      the current live substitution
    • copyCurrentSolution

      public Substitution copyCurrentSolution()
      Description copied from interface: SolutionManager
      Returns a stable snapshot of the current solution.
      Specified by:
      copyCurrentSolution in interface SolutionManager
      Returns:
      a defensive copy of the current solution (safe to keep).
    • next

      public boolean next(int level)
      Description copied from interface: SolutionManager
      Advance the iterator at level so the next candidate substitution (if any) is merged into the global solution.
      Specified by:
      next in interface SolutionManager
      Parameters:
      level - depth in the search tree (0‑based)
      Returns:
      true if a compatible substitution exists, false otherwise.
    • add

      public void add(int level, Spliterator<Substitution> substitutions, Collection<Variable> newVariables)
      Description copied from interface: SolutionManager
      Register the spliterator that will supply substitutions for level together with the
      list of variables that those substitutions can bind for the first time.
      Specified by:
      add in interface SolutionManager
      Parameters:
      level - depth in the search tree (0-based)
      substitutions - the substitutions available at that level
      newVariables - the variables that may become bound at that level
    • getSpliterator

      public Spliterator<Substitution> getSpliterator(int level)
      Description copied from interface: SolutionManager
      Returns the spliterator registered for a level.
      Specified by:
      getSpliterator in interface SolutionManager
      Parameters:
      level - depth in the search tree (0-based)
      Returns:
      the spliterator associated with level, or null.
    • replaceSpliterator

      public void replaceSpliterator(int level, Spliterator<Substitution> newSpliterator)
      Description copied from interface: SolutionManager
      Replaces the spliterator registered for a level. Replace the spliterator stored for level.
      Specified by:
      replaceSpliterator in interface SolutionManager
      Parameters:
      level - depth in the search tree (0-based)
      newSpliterator - the replacement spliterator
    • pruneOtherIterators

      public void pruneOtherIterators(int level)
      Description copied from interface: SolutionManager
      Prunes every stored iterator except the selected level. Remove (or empty) every level that is not equal to level.
      Specified by:
      pruneOtherIterators in interface SolutionManager
      Parameters:
      level - the level to keep
    • deepCopy

      public SolutionManager deepCopy()
      Description copied from interface: SolutionManager
      Creates an independent copy of this solution manager.
      Specified by:
      deepCopy in interface SolutionManager
      Returns:
      an independent copy of this manager so that another branch can evolve in parallel without interference.
    • toString

      public String toString()
      Overrides:
      toString in class Object