@Test public void testRemoveVertex() { construtGraph(); graph.removeVertex(4); assertEquals(graph.getVertexNumber(), 9); assertEquals(graph.getEdgeNumber(), 6); graph.removeVertex(6); assertEquals(graph.getVertexNumber(), 8); assertEquals(graph.getEdgeNumber(), 5); graph.removeVertex(8); assertEquals(graph.getVertexNumber(), 7); assertEquals(graph.getEdgeNumber(), 5); graph.removeVertex(9); assertEquals(graph.getVertexNumber(), 6); assertEquals(graph.getEdgeNumber(), 5); graph.removeVertex(1); assertEquals(graph.getVertexNumber(), 5); assertEquals(graph.getEdgeNumber(), 3); graph.removeVertex(3); assertEquals(graph.getVertexNumber(), 4); assertEquals(graph.getEdgeNumber(), 2); graph.removeVertex(2); assertEquals(graph.getVertexNumber(), 3); assertEquals(graph.getEdgeNumber(), 1); graph.removeVertex(7); assertEquals(graph.getVertexNumber(), 2); assertEquals(graph.getEdgeNumber(), 0); graph.removeVertex(5); assertEquals(graph.getVertexNumber(), 1); assertEquals(graph.getEdgeNumber(), 0); graph.removeVertex(10); assertEquals(graph.getVertexNumber(), 0); assertEquals(graph.getEdgeNumber(), 0); }
public synchronized void removeVertex(VK key) { List<Map.Entry<VK, VK>> pairs = new ArrayList<>(); for (VK postKey : getPostNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(key, postKey)); } for (VK preKey : getPreNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(preKey, key)); } for (Map.Entry<VK, VK> pair : pairs) { removeEdge(pair.getKey(), pair.getValue()); } vertices.remove(key); }
Graph { public synchronized void removeVertex(VK key) { List<Map.Entry<VK, VK>> pairs = new ArrayList<>(); for (VK postKey : getPostNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(key, postKey)); } for (VK preKey : getPreNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(preKey, key)); } for (Map.Entry<VK, VK> pair : pairs) { removeEdge(pair.getKey(), pair.getValue()); } vertices.remove(key); } }
Graph { public synchronized void removeVertex(VK key) { List<Map.Entry<VK, VK>> pairs = new ArrayList<>(); for (VK postKey : getPostNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(key, postKey)); } for (VK preKey : getPreNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(preKey, key)); } for (Map.Entry<VK, VK> pair : pairs) { removeEdge(pair.getKey(), pair.getValue()); } vertices.remove(key); } Graph(); }
Graph { public synchronized void removeVertex(VK key) { List<Map.Entry<VK, VK>> pairs = new ArrayList<>(); for (VK postKey : getPostNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(key, postKey)); } for (VK preKey : getPreNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(preKey, key)); } for (Map.Entry<VK, VK> pair : pairs) { removeEdge(pair.getKey(), pair.getValue()); } vertices.remove(key); } Graph(); synchronized void addVertex(VK key, VD vertex); synchronized void addVertexIfAbsent(VK key, VD vertex); synchronized void removeVertex(VK key); boolean addEdge(VK start, VK end); boolean addEdge(VK start, VK end, boolean createVertex); boolean addEdge(VK start, VK end, ED edge); synchronized boolean addEdge(VK start, VK end, ED edge, boolean createVertex); synchronized void removeEdge(VK start, VK end); boolean forceRefreshPreEdges(Collection<VK> addStartKeys,
                                      VK endKey); synchronized boolean forceRefreshPreEdges(Collection<VK> addStartKeys,
                                                   VK endKey,
                                                   boolean createVertex); boolean addRemoveMultiEdges(Collection<VK> removeStartKeys,
                                     Collection<VK> addStartKeys,
                                     VK endKey); synchronized boolean addRemoveMultiEdges(Collection<VK> removeStartKeys,
                                                  Collection<VK> addStartKeys,
                                                  VK endKey,
                                                  boolean createVertex); synchronized void clear(); synchronized boolean containsVertex(VK key); synchronized VD getVertex(VK key); Map<VK, VD> getVertices(); synchronized boolean containsEdge(VK startKey, VK endKey); Map<VK, Map<VK, ED>> getEdges(); synchronized ED getEdge(VK startKey, VK endKey); synchronized int getEdgeNumber(); int getVertexNumber(); synchronized Collection<VK> getStartVertex(); synchronized Collection<VK> getEndVertex(); Set<VK> getPreNode(VK key); Map<VK, ED> getPreNodeAttr(VK key); Set<VK> getPostNode(VK key); Map<VK, ED> getPostNodeAttr(VK key); synchronized int getIndegree(VK key); synchronized int getOutdegree(VK key); boolean hasCycle(); List<VK> broadFirstSearch(); List<VK> depthFirstSearch(); List<VK> topologicalSort(); synchronized boolean isConnected(); }
Graph { public synchronized void removeVertex(VK key) { List<Map.Entry<VK, VK>> pairs = new ArrayList<>(); for (VK postKey : getPostNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(key, postKey)); } for (VK preKey : getPreNode(key)) { pairs.add(new AbstractMap.SimpleEntry<>(preKey, key)); } for (Map.Entry<VK, VK> pair : pairs) { removeEdge(pair.getKey(), pair.getValue()); } vertices.remove(key); } Graph(); synchronized void addVertex(VK key, VD vertex); synchronized void addVertexIfAbsent(VK key, VD vertex); synchronized void removeVertex(VK key); boolean addEdge(VK start, VK end); boolean addEdge(VK start, VK end, boolean createVertex); boolean addEdge(VK start, VK end, ED edge); synchronized boolean addEdge(VK start, VK end, ED edge, boolean createVertex); synchronized void removeEdge(VK start, VK end); boolean forceRefreshPreEdges(Collection<VK> addStartKeys,
                                      VK endKey); synchronized boolean forceRefreshPreEdges(Collection<VK> addStartKeys,
                                                   VK endKey,
                                                   boolean createVertex); boolean addRemoveMultiEdges(Collection<VK> removeStartKeys,
                                     Collection<VK> addStartKeys,
                                     VK endKey); synchronized boolean addRemoveMultiEdges(Collection<VK> removeStartKeys,
                                                  Collection<VK> addStartKeys,
                                                  VK endKey,
                                                  boolean createVertex); synchronized void clear(); synchronized boolean containsVertex(VK key); synchronized VD getVertex(VK key); Map<VK, VD> getVertices(); synchronized boolean containsEdge(VK startKey, VK endKey); Map<VK, Map<VK, ED>> getEdges(); synchronized ED getEdge(VK startKey, VK endKey); synchronized int getEdgeNumber(); int getVertexNumber(); synchronized Collection<VK> getStartVertex(); synchronized Collection<VK> getEndVertex(); Set<VK> getPreNode(VK key); Map<VK, ED> getPreNodeAttr(VK key); Set<VK> getPostNode(VK key); Map<VK, ED> getPostNodeAttr(VK key); synchronized int getIndegree(VK key); synchronized int getOutdegree(VK key); boolean hasCycle(); List<VK> broadFirstSearch(); List<VK> depthFirstSearch(); List<VK> topologicalSort(); synchronized boolean isConnected();  }