-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Closed
Closed
Copy link
Labels
P4no SLOno SLOpackage=graphstatus=triagedtype=enhancementMake an existing feature betterMake an existing feature better
Milestone
Description
I recently found myself writing this code.
MutableGraph<Integer> graph = GraphBuilder.undirected().build();
graph.addNode(1);
Set<Integer> adjacentNodesView = graph.adjacentNodes(1);
System.out.println(graph.edges()); // []
System.out.println(adjacentNodesView); // []
System.out.println(graph.adjacentNodes(1)); // []
graph.putEdge(1, 2);
System.out.println(graph.edges()); // [[2, 1]]
System.out.println(adjacentNodesView); // [2]
System.out.println(graph.adjacentNodes(1)); // [2]
graph.removeNode(1);
System.out.println(graph.edges()); // []
System.out.println(adjacentNodesView); // [2] <-- Unexpected! Should be []?
System.out.println(graph.adjacentNodes(1)); // throws IAEI was surprised by the contents of adjacentNodesView at the end, because if graph.edges() is cleared, then I intuitively expected the adjacent nodes to be cleared too.
But then I thought about it some more and realised this is a weird grey area, because if a user calls graph.adjacentNodes(1) again, then an IAE is rightfully thrown to prevent bugs.
I'm torn between adjacentNodesView being [] or [2] in this case.
@jrtom, what do you think?
Koslx888
Metadata
Metadata
Assignees
Labels
P4no SLOno SLOpackage=graphstatus=triagedtype=enhancementMake an existing feature betterMake an existing feature better