Skip to content

Commit aa022bc

Browse files
author
VincentDerk
committed
Bugfix: fix root layer ix. Does not resolve the issue of ``how does user know which output is what, when there are duplicate root nodes''.
1 parent 5b7dca1 commit aa022bc

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/circuit.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,18 @@ void Circuit::add_root(Node* new_root) {
382382

383383

384384
if (new_root->layer != 0) {
385-
for (size_t i = 0; i < roots.size(); ++i)
386-
roots[i]->ix = i;
385+
// root layer's order might have changed:
386+
// set ix back to those according to `roots` list.
387+
// Since `roots` may contain duplicate node refs:
388+
// we first set all ix to -1 to detect the duplicate refs.
389+
for (size_t i = 0; i < roots.size(); ++i)
390+
roots[i]->ix = -1;
391+
392+
int root_idx = 0;
393+
for (size_t i = 0; i < roots.size(); ++i) {
394+
if (roots[i]->ix == -1)
395+
roots[i]->ix = root_idx++;
396+
}
387397
}
388398

389399
/*

0 commit comments

Comments
 (0)