#include "circuit.h" #include #include void Circuit::cal_topo_index() { int topo = 1; std::queue q; std::unordered_map ins; for(Gate* gate : gates) { ins[gate] = gate->inputs.size(); } for(auto in : PIs) { in->topo = topo++; q.push(in); } while(!q.empty()) { Gate* g = q.front(); q.pop(); for(Gate* out : g->outputs) { ins[out]--; if(ins[out] == 0) { out->topo = topo++; q.push(out); } } } }