code: public static <T> HashSet<T> dfs(T root, Set<T> visited, Deps<T> deps) {
          // The set of leaves (excluding any which were already marked as visited).
          HashSet<T> leaves = new HashSet<T>();
          // The stack for DFS.
          Stack<T> stack = new Stack<T>();
          stack.push(root);
          while (stack.size() > 0) {
              T p = stack.pop();
              if (visited.add(p)) {
                  // Unseen.
                  if (deps.getDeps(p).size() == 0) {
                      // Is leaf.
                      leaves.add(p);
                  } else {
                      // Not a leaf.
                      stack.addAll(deps.getDeps(p));
                  }
              } else {
                  // Seen.
                  continue;
              }
          }
          return leaves;
      }
docs: TODO: detect cycles.