Package io.github.nhtc2005.alns.memory
Class HashSetVisitedSolutionTracker<K,S extends Solution<S>>
java.lang.Object
io.github.nhtc2005.alns.memory.HashSetVisitedSolutionTracker<K,S>
- Type Parameters:
K- the key typeS- 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 Summary
ConstructorsConstructorDescriptionHashSetVisitedSolutionTracker(SolutionKey<K, S> solutionKey) Creates an empty tracker using the supplied key extractor. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of distinct keys recorded since the last reset.booleanrecordIfNew(S solution) Records a solution without modifying it and reports whether it is new to this tracker.voidreset()Removes all recorded keys.
-
Constructor Details
-
HashSetVisitedSolutionTracker
Creates an empty tracker using the supplied key extractor.- Parameters:
solutionKey- the extractor of non-null, stable solution keys- Throws:
NullPointerException- ifsolutionKeyis null
-
-
Method Details
-
recordIfNew
Records a solution without modifying it and reports whether it is new to this tracker.- Specified by:
recordIfNewin interfaceVisitedSolutionTracker<K>- Parameters:
solution- the non-null solution to record- Returns:
trueif newly recorded;falseif already recorded- Throws:
NullPointerException- if the solution or its extracted key is null
-
reset
public void reset()Removes all recorded keys.- Specified by:
resetin interfaceVisitedSolutionTracker<K>
-
getVisitedSolutionCount
public int getVisitedSolutionCount()Returns the number of distinct keys recorded since the last reset.- Returns:
- the recorded key count
-