You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not store before and after children in DiffNodes
Because the invariant
`node.getBeforeParent().getBeforeChildren().contains(node)`
holds for each `DiffNode node` the `beforeChildren` and `afterChildren`
lists can be computed and do not have to be stored.
By using this invariant, the check if a node is a before/after child can
be implemented in `O(1)` in contrast to the `O(n)` version which uses
the `beforeChildren` and `afterChildren` lists. This speedup is
especially important for parsing `DiffTree`s.
It is also possible to store `Set`s instead of `List`s for `DiffNode`
children to get a similar time complexity, but as demonstrated by this
commit that memory can be saved. If there is a need to compute a
`beforeChildren` or `afterChildren` set (these lists didn't actually
guarantee any ordering) more efficiently than by traversing
`childOrdering` (which requires about the double time) this would be a
valid approach.
@@ -733,16 +724,14 @@ public static DiffNode fromID(final int id, String label) {
733
724
734
725
publicvoidassertConsistency() {
735
726
// check consistency of children lists and edges
736
-
for (finalDiffNodebc : beforeChildren) {
737
-
Assert.assertTrue(bc.beforeParent == this, () -> "Before child " + bc + " of " + this + " has another parent " + bc.beforeParent + "!");
738
-
Assert.assertTrue(childOrder.contains(bc), () -> "Before child " + bc + " of " + this + " is not in the list of all children!");
739
-
}
740
-
for (finalDiffNodeac : afterChildren) {
741
-
Assert.assertTrue(ac.afterParent == this, () -> "After child " + ac + " of " + this + " has another parent " + ac.afterParent + "!");
742
-
Assert.assertTrue(childOrder.contains(ac), () -> "After child " + ac + " of " + this + " is not in the list of all children!");
743
-
}
744
727
for (finalDiffNodec : childOrder) {
745
-
Assert.assertTrue(beforeChildren.contains(c) || afterChildren.contains(c), () -> "Child " + c + " of " + this + " is neither a before not an after child!");
728
+
Assert.assertTrue(isChild(c), () -> "Child " + c + " of " + this + " is neither a before nor an after child!");
729
+
if (c.getBeforeParent() != null) {
730
+
Assert.assertTrue(c.getBeforeParent().isBeforeChild(c), () -> "The beforeParent of " + c + " doesn't contain that node as child");
731
+
}
732
+
if (c.getAfterParent() != null) {
733
+
Assert.assertTrue(c.getAfterParent().isAfterChild(c), () -> "The afterParent of " + c + " doesn't contain that node as child");
0 commit comments