Class HashSetVisitedSolutionTracker<K,S extends Solution<S>>

java.lang.Object
io.github.nhtc2005.alns.memory.HashSetVisitedSolutionTracker<K,S>
Type Parameters:
K - the key type
S - the solution type
All Implemented Interfaces:
VisitedSolutionTracker<S>

public final class HashSetVisitedSolutionTracker<K,S extends Solution<S>> extends Object implements VisitedSolutionTracker<S>
Tracks visits by storing extracted keys in a hash set.

Keys are retained until reset, so memory usage grows with the number of distinct keys. This tracker is mutable and must not be shared by concurrent runs.

  • Constructor Details

    • HashSetVisitedSolutionTracker

      public HashSetVisitedSolutionTracker(SolutionKey<K,S> solutionKey)
      Creates an empty tracker using the supplied key extractor.
      Parameters:
      solutionKey - the extractor of non-null, stable solution keys
      Throws:
      NullPointerException - if solutionKey is null
  • Method Details

    • recordIfNew

      public boolean recordIfNew(S solution)
      Records a solution without modifying it and reports whether it is new to this tracker.
      Specified by:
      recordIfNew in interface VisitedSolutionTracker<K>
      Parameters:
      solution - the non-null solution to record
      Returns:
      true if newly recorded; false if already recorded
      Throws:
      NullPointerException - if the solution or its extracted key is null
    • reset

      public void reset()
      Removes all recorded keys.
      Specified by:
      reset in interface VisitedSolutionTracker<K>
    • getVisitedSolutionCount

      public int getVisitedSolutionCount()
      Returns the number of distinct keys recorded since the last reset.
      Returns:
      the recorded key count