]> ruin.nu Git - germs.git/blobdiff - src/genealgorithms.cpp
inital commit of componenttree with associated changes
[germs.git] / src / genealgorithms.cpp
index ed68b67ab4b798483da9003dbb37478165ef760c..174c6f7b0414277b006b562f2736a83077db9fb7 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "genealgorithms.h"
 #include "geneorder.h"
+#include "componenttree.h"
 
 #include <algorithm>
 #include <set>
@@ -146,7 +147,7 @@ std::vector<Component> findComponents(const GeneOrder& go){
                        s = Sdir.top();
                }
                if (go[i] > 0 && dir[i] == dir[s] && static_cast<Gene>(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<Component> findComponents(const GeneOrder& go){
                        s = Srev.top();
                }
                if (go[i] < 0 && rev[i] == rev[s] && static_cast<Gene>(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<Interval> findIntervals(const GeneOrder& go){
-       size_t max = go.size();
+       const size_t max = go.size();
        vector<Interval> 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;
                        }
 
        }