Skip to content

Commit 6b2bcb0

Browse files
committed
feat: traversing variation trees in post-order
1 parent fa62e30 commit 6b2bcb0

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/org/variantsync/diffdetective/variation/tree/VariationNode.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,17 @@ public void forAllPreorder(Consumer<T> action) {
419419
}
420420
}
421421

422+
/**
423+
* Traverses all nodes in this subtree in postorder.
424+
*/
425+
public void forAllPostorder(Consumer<T> action) {
426+
for (var child : getChildren()) {
427+
child.forAllPostorder(action);
428+
}
429+
430+
action.accept(this.upCast());
431+
}
432+
422433
public void forMeAndMyAncestors(final Consumer<T> action) {
423434
action.accept(this.upCast());
424435
final T p = getParent();

src/main/java/org/variantsync/diffdetective/variation/tree/VariationTree.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public VariationDiff<L> toCompletelyUnchangedVariationDiff() {
151151
}
152152

153153
/**
154-
* Invokes the given callback for each node in this Variation Tree in depth-first order.
154+
* Invokes the given callback for each node in this Variation Tree in pre-order.
155155
* @param action callback
156156
* @return this
157157
*/
@@ -160,6 +160,16 @@ public VariationTree<L> forAllPreorder(final Consumer<VariationTreeNode<L>> acti
160160
return this;
161161
}
162162

163+
/**
164+
* Invokes the given callback for each node in this Variation Tree in post-order.
165+
* @param action callback
166+
* @return this
167+
*/
168+
public VariationTree<L> forAllPostorder(final Consumer<VariationTreeNode<L>> action) {
169+
root.forAllPostorder(action);
170+
return this;
171+
}
172+
163173
/**
164174
* Checks whether any node in this tree satisfies the given condition.
165175
* The condition might not be invoked on every node in case a node is found.

0 commit comments

Comments
 (0)