@@ -37,7 +37,7 @@ namespace refactor::graph_topo {
3737 Rc<Node> pushNode (TN, std::vector<Rc<Edge>>);
3838 void eraseNode (count_t );
3939 void eraseNode (Rc<Node>);
40- size_t cleanup (bool useless (TE const &) = nullptr);
40+ size_t cleanup (bool useful (TE const &) = nullptr);
4141 bool sort ();
4242 };
4343
@@ -86,6 +86,7 @@ namespace refactor::graph_topo {
8686 node.disconnect (i);
8787 }
8888 for (auto const &out : node._outputs ) {
89+ ASSERT (out->_targets .empty (), " Output edge should not have targets" );
8990 out->_source = nullptr ;
9091 }
9192 }
@@ -180,23 +181,22 @@ namespace refactor::graph_topo {
180181 _nodes.erase (it);
181182 }
182183
183- LINKED_GRAPH_FN cleanup (bool useless (TE const &))->size_t {
184+ LINKED_GRAPH_FN cleanup (bool useful (TE const &))->size_t {
184185 std::unordered_set<Edge *> outputs;
185186 outputs.reserve (_outputs.size ());
186187 std::transform (_outputs.begin (), _outputs.end (), std::inserter (outputs, outputs.end ()), [](auto const &e) { return e.get (); });
187- auto useful = [&](Rc<Edge> const &e) {
188- return !e->_targets .empty () || // 还有节点连接到这个边
189- outputs.contains (e.get ()) ||// 这个边是全图输出
190- !useless || // 不需要其他判断
191- !useless (e->_info ); // 这个边其他原因有用
188+ auto useful_ = [&](Rc<Edge> const &e) {
189+ return !e->_targets .empty () || // 还有节点连接到这个边
190+ outputs.contains (e.get ()) || // 这个边是全图输出
191+ (useful && useful (e->_info ));// 这个边其他原因有用
192192 };
193193
194194 auto before = _nodes.size ();
195195 while (true ) {
196196 auto endit = std::remove_if (
197197 _nodes.begin (), _nodes.end (),
198198 [&, this ](auto &n) {
199- auto useless_ = std::none_of (n->_outputs .begin (), n->_outputs .end (), useful );
199+ auto useless_ = std::none_of (n->_outputs .begin (), n->_outputs .end (), useful_ );
200200 if (useless_) { _cleanupNode (*n); }
201201 return useless_;
202202 });
0 commit comments