Skip to content

Commit

Permalink
Use std::queue to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu committed Dec 2, 2024
1 parent e0ab555 commit 0a52b1b
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions src/nrnoc/seclist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <../../nrnconf.h>

#include <queue>

#define HOC_L_LIST 1
#include "section.h"
#include "neuron.h"
Expand Down Expand Up @@ -65,16 +68,11 @@ static double append(void* v) {
return 1.;
}


static Item* children1(List* sl, Section* sec) {
Item* i;
Section* ch;
i = sl->prev;
for (ch = sec->child; ch; ch = ch->sibling) {
i = lappendsec(sl, ch);
static void children1(List* sl, Section* sec) {
for (Section* ch = sec->child; ch; ch = ch->sibling) {
lappendsec(sl, ch);

Check warning on line 73 in src/nrnoc/seclist.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrnoc/seclist.cpp#L71-L73

Added lines #L71 - L73 were not covered by tests
section_ref(ch);
}
return i;
}

static double children(void* v) {
Expand All @@ -86,23 +84,20 @@ static double children(void* v) {
return 1.;
}

static Item* subtree1(List* sl, Section* sec) {
Item *i, *j, *last, *first;
Section* s;
/* it is confusing to span the tree from the root without using
recursion.
*/
s = sec;
i = lappendsec(sl, s);
section_ref(s);
last = i->prev;
while (i != last) {
for (first = last->next, last = i, j = first; j->prev != last; j = j->next) {
s = hocSEC(j);
i = children1(sl, s);
static void subtree1(List* sl, Section* sec) {
lappendsec(sl, sec);
section_ref(sec);
std::queue<Section*> remainings{};
remainings.push(sec);
while (!remainings.empty()) {
Section* remain = remainings.front();
for (Section* ch = remain->child; ch; ch = ch->sibling) {
lappendsec(sl, ch);
remainings.push(ch);
section_ref(ch);
}
remainings.pop();
}
return i;
}

static double subtree(void* v) {
Expand Down

0 comments on commit 0a52b1b

Please sign in to comment.