Lines Matching refs:node
10 __slots__ = "node", "npredecessors", "successors"
12 def __init__(self, node):
13 # The node this class is augmenting.
14 self.node = node
18 # node is marked done by a call to done(), set to _NODE_DONE.
33 of nodes, such that each node is, in the graph, an immediate predecessor of the
34 next node in the list. In the reported list, the first and the last node will be
51 for node, predecessors in graph.items():
52 self.add(node, *predecessors)
54 def _get_nodeinfo(self, node):
55 if (result := self._node2info.get(node)) is None:
56 self._node2info[node] = result = _NodeInfo(node)
59 def add(self, node, *predecessors):
60 """Add a new node and its predecessors to the graph.
62 Both the *node* and all elements in *predecessors* must be hashable.
64 If called multiple times with the same node argument, the set of dependencies
67 It is possible to add a node with no dependencies (*predecessors* is not provided)
68 as well as provide a dependency twice. If a node that has not been provided before
77 # Create the node -> predecessor edges
78 nodeinfo = self._get_nodeinfo(node)
81 # Create the predecessor -> node edges
84 pred_info.successors.append(node)
98 i.node for i in self._node2info.values() if i.npredecessors == 0
124 for node in result:
125 n2i[node].npredecessors = _NODE_OUT
154 This method unblocks any successor of each node in *nodes* for being returned
157 Raises :exec:`ValueError` if any node in *nodes* has already been marked as
158 processed by a previous call to this method, if a node was not added to the
160 node has not yet been returned by "get_ready".
168 for node in nodes:
170 # Check if we know about this node (it was added previously using add()
171 if (nodeinfo := n2i.get(node)) is None:
172 raise ValueError(f"node {node!r} was not added using add()")
174 # If the node has not being returned (marked as ready) previously, inform the user.
179 f"node {node!r} was not passed out (still not ready)"
182 raise ValueError(f"node {node!r} was already marked done")
184 assert False, f"node {node!r}: unknown status {stat}"
186 # Mark the node as processed
205 for node in n2i:
206 if node in seen:
210 if node in seen:
211 # If we have seen already the node and is in the
213 if node in node2stacki:
214 return stack[node2stacki[node] :] + [node]
217 seen.add(node)
218 itstack.append(iter(n2i[node].successors).__next__)
219 node2stacki[node] = len(stack)
220 stack.append(node)
226 node = itstack[-1]()