@Test public void testTopologicalSort() { clearAndTest(); graph.addEdge(1, 2, null, true); graph.addEdge(1, 6, null, true); graph.addEdge(2, 3, null, true); graph.addEdge(3, 4, null, true); graph.addEdge(3, 6, null, true); graph.addEdge(4, 5, null, true); graph.addEdge(5, 3, null, true); graph.addEdge(5, 6, null, true); graph.addEdge(7, 6, null, true); try { graph.topologicalSort(); assertTrue(false); } catch (Exception e) { assertTrue(true); } graph.removeEdge(3, 4); try { List<Integer> entry = graph.topologicalSort(); List l = entry.subList(0, 3); assertTrue(l.contains(1) && l.contains(7) && l.contains(4)); l = entry.subList(3, 5); assertTrue(l.contains(2) && l.contains(5)); assertTrue(entry.get(5) == 3); assertTrue(entry.get(6) == 6); } catch (Exception e) { assertTrue(false); } }
public List<VK> topologicalSort() throws Exception { Map.Entry<Boolean, List<VK>> entry = topologicalSortImpl(); if (entry.getKey()) { return entry.getValue(); } throw new Exception("Graph has a cycle, can't compute topological sort."); }
Graph { public List<VK> topologicalSort() throws Exception { Map.Entry<Boolean, List<VK>> entry = topologicalSortImpl(); if (entry.getKey()) { return entry.getValue(); } throw new Exception("Graph has a cycle, can't compute topological sort."); } }
Graph { public List<VK> topologicalSort() throws Exception { Map.Entry<Boolean, List<VK>> entry = topologicalSortImpl(); if (entry.getKey()) { return entry.getValue(); } throw new Exception("Graph has a cycle, can't compute topological sort."); } Graph(); }
Graph { public List<VK> topologicalSort() throws Exception { Map.Entry<Boolean, List<VK>> entry = topologicalSortImpl(); if (entry.getKey()) { return entry.getValue(); } throw new Exception("Graph has a cycle, can't compute topological sort."); } 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 List<VK> topologicalSort() throws Exception { Map.Entry<Boolean, List<VK>> entry = topologicalSortImpl(); if (entry.getKey()) { return entry.getValue(); } throw new Exception("Graph has a cycle, can't compute topological sort."); } 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();  }