(graph, callback)
| 42 | } |
| 43 | |
| 44 | const enhancedDepthFirstSearch = (graph, callback) => { |
| 45 | const vertices = graph.vertices; |
| 46 | const adjList = graph.adjList; |
| 47 | const color = initializeColor(vertices); |
| 48 | const discovery = {}; // Discovery times |
| 49 | const finished = {}; // Finish times |
| 50 | const predecessors = {}; |
| 51 | const time = { count: 0 }; |
| 52 | |
| 53 | for (let i = 0; i < vertices.length; i++) { |
| 54 | finished[vertices[i]] = 0; |
| 55 | discovery[vertices[i]] = 0; |
| 56 | predecessors[vertices[i]] = null; |
| 57 | } |
| 58 | |
| 59 | for (let i = 0; i < vertices.length; i++) { |
| 60 | if (color[vertices[i]] === Colors.WHITE) { |
| 61 | enhancedDFSVisit(vertices[i], color, discovery, finished, predecessors, time, adjList); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return { discovery, finished, predecessors}; |
| 66 | } |
| 67 | |
| 68 | const enhancedDFSVisit = (vertex, color, discovery, finished, predecessors, time, adjList) => { |
| 69 | color[vertex] = Colors.GREY; |
no test coverage detected