Skip to content

Commit

Permalink
fix(codegen): Allow multiple paths for a shape (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikKapila authored Jan 9, 2025
1 parent 7a86bc8 commit 3540436
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ public static Set<List<ShapeId>> findAllDependentShapesWithPaths(
Set<List<ShapeId>> pathsToShapes = new LinkedHashSet<>(
new LinkedHashSet<>()
);
Set<ShapeId> visited = new HashSet<>();

// Breadth-first search via getDependencyShapeIds
final Queue<List<ShapeId>> toTraverse = new LinkedList<>(
Expand All @@ -470,16 +469,16 @@ public static Set<List<ShapeId>> findAllDependentShapesWithPaths(
while (!toTraverse.isEmpty()) {
final List<ShapeId> currentShapeIdWithPath = toTraverse.remove();

// to avoid cycles, only keep the first list with a given last element
ShapeId last = currentShapeIdWithPath.get(
currentShapeIdWithPath.size() - 1
);
if (visited.add(last) && pathsToShapes.add(currentShapeIdWithPath)) {
if (pathsToShapes.add(currentShapeIdWithPath)) {
final Shape currentShape = model.expectShape(
currentShapeIdWithPath.get(currentShapeIdWithPath.size() - 1)
);
final List<List<ShapeId>> dependencyShapeIdsWithPaths =
getDependencyShapeIds(currentShape)
// to avoid cycles, append only those dependencyShapeId which are not already in the path currentShapeIdWithPath
.filter(dependencyShapeId ->
!currentShapeIdWithPath.contains(dependencyShapeId)
)
.map(dependencyShapeId ->
Stream
.concat(
Expand Down

0 comments on commit 3540436

Please sign in to comment.