MCPcopy Index your code
hub / github.com/careercup/ctci / hasCycle

Method hasCycle

java/Chapter 16/Question16_4/LockFactory.java:38–49  ·  view source on GitHub ↗
(Hashtable<Integer, Boolean> touchedNodes, int[] resourcesInOrder)

Source from the content-addressed store, hash-verified

36 }
37
38 public boolean hasCycle(Hashtable<Integer, Boolean> touchedNodes, int[] resourcesInOrder) {
39 /* check for a cycle */
40 for (int resource : resourcesInOrder) {
41 if (touchedNodes.get(resource) == false) {
42 LockNode n = locks[resource];
43 if (n.hasCycle(touchedNodes)) {
44 return true;
45 }
46 }
47 }
48 return false;
49 }
50
51 /* To prevent deadlocks, force the processes to declare upfront what order they will
52 * need the locks in. Verify that this order does not create a deadlock (a cycle in a directed graph)

Callers 1

declareMethod · 0.95

Calls 2

hasCycleMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected