Lines Matching refs:node

47      * Add a node to the graph.
49 * <p>If the node already exists in the graph then this method is a no-op.</p>
51 * @param node the node to add
53 public void addNode(@NonNull T node) {
54 if (!mGraph.containsKey(node)) {
55 mGraph.put(node, null);
60 * Returns true if the node is already present in the graph, false otherwise.
62 public boolean contains(@NonNull T node) {
63 return mGraph.containsKey(node);
72 * @param node the parent node
73 * @param incomingEdge the node which has is an incoming edge to {@code node}
75 public void addEdge(@NonNull T node, @NonNull T incomingEdge) {
76 if (!mGraph.containsKey(node) || !mGraph.containsKey(incomingEdge)) {
81 ArrayList<T> edges = mGraph.get(node);
85 mGraph.put(node, edges);
92 * Get any incoming edges from the given node.
97 public List getIncomingEdges(@NonNull T node) {
98 return mGraph.get(node);
102 * Get any outgoing edges for the given node (i.e. nodes which have an incoming edge
103 * from the given node).
108 public List<T> getOutgoingEdges(@NonNull T node) {
112 if (edges != null && edges.contains(node)) {
123 * Checks whether we have any outgoing edges for the given node (i.e. nodes which have
124 * an incoming edge from the given node).
126 * @return <code>true</code> if the node has any outgoing edges, <code>false</code>
129 public boolean hasOutgoingEdges(@NonNull T node) {
132 if (edges != null && edges.contains(node)) {
157 * <p>The resulting list will be ordered such that index 0 will contain the node at the bottom
158 * of the graph. The node at the end of the list will have no dependencies on other nodes.</p>
165 // Start a DFS from each node in the graph
173 private void dfs(final T node, final ArrayList<T> result, final HashSet<T> tmpMarked) {
174 if (result.contains(node)) {
175 // We've already seen and added the node to the result list, skip...
178 if (tmpMarked.contains(node)) {
181 // Temporarily mark the node
182 tmpMarked.add(node);
183 // Recursively dfs all of the node's edges
184 final ArrayList<T> edges = mGraph.get(node);
190 // Unmark the node from the temporary list
191 tmpMarked.remove(node);
193 result.add(node);