[docs]defresume_with_new_graph(self,graph:networkx.DiGraph)->bool:""" We can only reasonably reuse existing results if the node index of the already traversed nodes are the same as the ones from the new graph. Otherwise, we always restart. :return: True if we are resuming, False if reset() is called. """# update the graphself.graph=graphmust_restart=Falsenew_sorted_nodes=list(self.sort_nodes())# check if new sorted_nodes is an extension of the existing sorted_nodesiflen(new_sorted_nodes)<len(self._sorted_nodes):must_restart=Trueelse:must_restart=notnew_sorted_nodes[:len(self._sorted_nodes)]==self._sorted_nodesifmust_restart:_l.debug("Cannot resume for function %r with the new graph.",self.function)self.reset()returnFalse# update related data structuresfori,ninenumerate(new_sorted_nodes):ifi>=len(self._sorted_nodes):self._node_to_index[n]=i# update worklist and nodes_setforninnew_sorted_nodes[len(self._sorted_nodes):]:self.revisit_node(n)# update sorted_nodes in the endself._sorted_nodes=new_sorted_nodesreturnTrue