X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fgenealgorithms.cpp;h=174c6f7b0414277b006b562f2736a83077db9fb7;hb=6ba92ada02bfbb04abb8a0c7a039ec63c7c9921e;hp=ed68b67ab4b798483da9003dbb37478165ef760c;hpb=7e811915a713eeef44f03385a1fc1f74a5301c30;p=germs.git diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index ed68b67..174c6f7 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -20,6 +20,7 @@ #include "genealgorithms.h" #include "geneorder.h" +#include "componenttree.h" #include #include @@ -146,7 +147,7 @@ std::vector findComponents(const GeneOrder& go){ s = Sdir.top(); } if (go[i] > 0 && dir[i] == dir[s] && static_cast(i - s) == p[i] - p[s]) - components.push_back(Component(p[s],p[i],(s+1 == i ? 0 : os[s]))); + components.push_back(Component(p[s],p[i],(s+1 == i ? 0 : os[s]),s,i)); //Reverse if (p[i-1] < p[i]) @@ -162,7 +163,7 @@ std::vector findComponents(const GeneOrder& go){ s = Srev.top(); } if (go[i] < 0 && rev[i] == rev[s] && static_cast(i - s) == p[s] - p[i]) - components.push_back(Component(-p[s],-p[i],(s+1 == i ? 0 : os[s]))); + components.push_back(Component(-p[s],-p[i],(s+1 == i ? 0 : os[s]),s,i)); //Update stacks if (go[i] > 0) @@ -182,26 +183,29 @@ int sign2(Gene g){ * */ std::vector findIntervals(const GeneOrder& go){ - size_t max = go.size(); + const size_t max = go.size(); vector intervals(go.size()-1,Interval(max,max,false)); size_t n = 0; - for (GeneOrder::iterator g = go.begin(); g != go.end(); ++g, ++n){ + const GeneOrder::iterator end = go.end(); + for (GeneOrder::iterator g = go.begin(); g != end; ++g, ++n){ size_t i = abs(*g); - if (i < go.size() - 1){ - intervals[i].first = n + (*g >= 0 ? 1 : 0); + if (i < max - 1){ + Interval& curr = intervals[i]; + curr.first = n + (*g >= 0 ? 1 : 0); - if (intervals[i].second == max) - intervals[i].oriented = *g < 0; + if (curr.second == max) + curr.oriented = *g < 0; else - intervals[i].oriented ^= *g < 0; + curr.oriented ^= *g < 0; } if (i > 0){ - intervals[i-1].second = n + (*g < 0 ? 1 : 0); + Interval& prev = intervals[i-1]; + prev.second = n + (*g < 0 ? 1 : 0); - if (intervals[i-1].first == max) - intervals[i-1].oriented = *g < 0; + if (prev.first == max) + prev.oriented = *g < 0; else - intervals[i-1].oriented ^= *g < 0; + prev.oriented ^= *g < 0; } }