Skip to content

Commit 3dd102b

Browse files
ibbempmbittner
authored andcommitted
refactor: Use identity checks instead of DiffNode.getID
1 parent c941d5c commit 3dd102b

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/main/java/org/variantsync/diffdetective/variation/diff/DiffTree.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private enum VisitStatus {
359359
ALL_PATHS_END_AT_ROOT,
360360
NOT_ALL_PATHS_END_AT_ROOT
361361
}
362-
private final Map<Integer, VisitStatus> cache = new HashMap<>();
362+
private final Map<DiffNode, VisitStatus> cache = new HashMap<>();
363363
private final DiffNode root;
364364

365365
private AllPathsEndAtRoot(final DiffNode root) {
@@ -375,11 +375,10 @@ public boolean test(final DiffNode d) {
375375
return true;
376376
}
377377

378-
final int id = d.getID();
379-
return switch (cache.getOrDefault(id, VisitStatus.STRANGER)) {
378+
return switch (cache.getOrDefault(d, VisitStatus.STRANGER)) {
380379
case STRANGER -> {
381380
// The stranger is now known.
382-
cache.putIfAbsent(id, VisitStatus.VISITED);
381+
cache.putIfAbsent(d, VisitStatus.VISITED);
383382

384383
final DiffNode b = d.getParent(BEFORE);
385384
final DiffNode a = d.getParent(AFTER);
@@ -397,7 +396,7 @@ public boolean test(final DiffNode d) {
397396
}
398397

399398
// Now we also know the result for the stranger.
400-
cache.put(id, result ? VisitStatus.ALL_PATHS_END_AT_ROOT : VisitStatus.NOT_ALL_PATHS_END_AT_ROOT);
399+
cache.put(d, result ? VisitStatus.ALL_PATHS_END_AT_ROOT : VisitStatus.NOT_ALL_PATHS_END_AT_ROOT);
401400
yield result;
402401
}
403402
// We detected a cycle because we visited a node but did not determine its value yet!

src/main/java/org/variantsync/diffdetective/variation/diff/traverse/DiffTreeTraversal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author Paul Bittner
2323
*/
2424
public class DiffTreeTraversal {
25-
private final Set<Integer> visited;
25+
private final Set<DiffNode> visited;
2626
private final DiffTreeVisitor visitor;
2727

2828
private DiffTreeTraversal(final DiffTreeVisitor visitor) {
@@ -86,6 +86,6 @@ public void visitChildrenOf(final DiffNode subtree) {
8686
* False if the node was already marked visited.
8787
*/
8888
private boolean markAsVisited(final DiffNode node) {
89-
return visited.add(node.getID());
89+
return visited.add(node);
9090
}
9191
}

0 commit comments

Comments
 (0)