@@ -64,7 +64,7 @@ class Engine(context: EngineContext) {
6464 logger.warn(exception.getMessage)
6565 }
6666 }
67- result
67+ deduplicate( result.toVector).toList
6868 }
6969
7070 private def newTasksFromResults (resultsOfTask : Vector [ReachableByResult ],
@@ -214,6 +214,30 @@ object Engine {
214214 .argument(param.order)
215215 .l
216216
217+ def deduplicate (vec : Vector [ReachableByResult ]): Vector [ReachableByResult ] = {
218+ vec
219+ .groupBy { x =>
220+ (x.path.headOption ++ x.path.lastOption, x.partial, x.callDepth)
221+ }
222+ .map {
223+ case (_, list) =>
224+ val lenIdPathPairs = list.map(x => (x.path.length, x)).toList
225+ val withMaxLength = (lenIdPathPairs.sortBy(_._1).reverse match {
226+ case Nil => Nil
227+ case h :: t => h :: t.takeWhile(y => y._1 == h._1)
228+ }).map(_._2)
229+
230+ if (withMaxLength.length == 1 ) {
231+ withMaxLength.head
232+ } else {
233+ withMaxLength.minBy { x =>
234+ x.path.map(_.node.id()).mkString(" -" )
235+ }
236+ }
237+ }
238+ .toVector
239+ }
240+
217241}
218242
219243case class EngineContext (semantics : Semantics , config : EngineConfig = EngineConfig ())
@@ -301,28 +325,7 @@ private class ReachableByCallable(task: ReachableByTask, context: EngineContext)
301325 endStates ++ retsToResolve
302326 }
303327
304- val res = (resultsForParents ++ resultsForCurNode)
305- .groupBy { x =>
306- (x.path.headOption ++ x.path.lastOption, x.partial, x.callDepth)
307- }
308- .map {
309- case (_, list) =>
310- val lenIdPathPairs = list.map(x => (x.path.length, x)).toList
311- val withMaxLength = (lenIdPathPairs.sortBy(_._1).reverse match {
312- case Nil => Nil
313- case h :: t => h :: t.takeWhile(y => y._1 == h._1)
314- }).map(_._2)
315-
316- if (withMaxLength.length == 1 ) {
317- withMaxLength.head
318- } else {
319- withMaxLength.minBy { x =>
320- x.path.map(_.node.id()).mkString(" -" )
321- }
322- }
323- }
324- .toVector
325-
328+ val res = deduplicate(resultsForParents ++ resultsForCurNode)
326329 table.add(curNode, res)
327330 res
328331 }
0 commit comments