Skip to content

Commit 7043fae

Browse files
committed
Refactor Starfold to adhere to DiffNode's invariants
The time specific children of `DiffNode` do not guarantee any ordering, but the Starfold transformation requires these nodes to be ordered: - When `respectNodeOrder` is active. - For the label of the merged node, which is composed sequentially from the merged nodes in the order of the given children. For that reason Starfold cannot use `DiffNode.getChildren` and has to use `DiffNode.getAllChildren` instead. Because this list contains both /before/ and /after/ children the actual computation has to filter the children to a specific time. It would also be possible to run the two cases (/before/ and /after/) in parallel, but this a consumer with the semantic of a coroutine and a finalisation step to merge the remaining nodes. But this introduces complexity which doesn't seem adequate.
1 parent 3cb5ec8 commit 7043fae

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/main/java/org/variantsync/diffdetective/diff/difftree/DiffNode.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,18 @@ public Node getPresenceCondition(Time time) {
644644
);
645645
}
646646

647+
public boolean isBeforeChild(DiffNode child) {
648+
return beforeChildren.contains(child);
649+
}
650+
651+
public boolean isAfterChild(DiffNode child) {
652+
return afterChildren.contains(child);
653+
}
654+
655+
public boolean isChild(DiffNode child, Time time) {
656+
return time.match(isBeforeChild(child), isAfterChild(child));
657+
}
658+
647659
public boolean isLeaf() {
648660
return childOrder.isEmpty();
649661
}

src/main/java/org/variantsync/diffdetective/diff/difftree/transform/Starfold.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ public void foldStar(final DiffNode starRoot) {
4747
public void foldStarAtTime(final DiffNode starRoot, Time time) {
4848
// System.out.println("Fold " + starRoot + " at time " + time);
4949
final DiffType targetDiffType = DiffType.thatExistsOnlyAt(time);
50-
51-
final List<DiffNode> children = starRoot.getChildren(time);
5250
final List<DiffNode> starArms = new ArrayList<>();
5351

54-
for (DiffNode child : children) {
52+
for (DiffNode child : starRoot.getAllChildren()) {
53+
if (!starRoot.isChild(child, time)) {
54+
continue;
55+
}
56+
5557
if (isStarArm(child) && child.diffType == targetDiffType) {
5658
// System.out.println(" Found arm " + child);
5759
starArms.add(child);

0 commit comments

Comments
 (0)