// always keeps a dynamically updated list of the n most probable // results // not synchronized srecord noeq PSCollectMostProbable(IProbabilisticScheduler ps, int maxResults, IVF1> action) implements IF0>> { TreeSetWithDuplicates> results = new(reverseComparator()); void add(WithProbability> result) { if (result == null) ret; results.add(result); truncateTreeSetWithDuplicates(results, maxResults); } selfType run() { action.get(result -> add(WithProbability(ps.currentProbability(), result)); this; } // results sorted by probability. instant public Set> results aka get() { ret results; } }