]> ruin.nu Git - germs.git/blobdiff - src/genealgorithms.cpp
Forgot to update the comment
[germs.git] / src / genealgorithms.cpp
index 4315cb391e46bfad6c7d10073ee485f2962a4158..e96c9be63e9d378187a0d58b9413905bf6517e20 100644 (file)
@@ -112,38 +112,22 @@ std::vector<Interval> findIntervals(const GeneOrder& go){
 }
 
 /**
- * TODO: Think of a better than O(n^2) implementation.
- * Possibly move to cache result
+ * 
  */
 std::vector<Interval> findIntervalsAtPoints(const vector<Interval>& intervals){
-       vector<Interval> points;
-       points.push_back(Interval(intervals.size(),intervals.size())); //Dummy interval to match point and index
-       for (size_t p = 1; p <= intervals.size(); ++p){
-               size_t f = 0;
-               size_t s = 0;
-               bool found = false;
-               size_t n = 0;
-               for (vector<Interval>::const_iterator i = intervals.begin(); i != intervals.end(); ++i, ++n){
-                       if (i->first == p){
-                               if (!found){
-                                       f = n;
-                                       found = true;
-                               }else{
-                                       s = n;
-                                       break;
-                               }
-                       }
-                       if (i->second == p){
-                               if (!found){
-                                       f = n;
-                                       found = true;
-                               }else{
-                                       s = n;
-                                       break;
-                               }
-                       }
-               }
-               points.push_back(Interval(f,s));
+       size_t max = intervals.size()+1;
+       vector<Interval> points(max,Interval(max,max));
+       size_t n = 0;
+       for (vector<Interval>::const_iterator i = intervals.begin(); i != intervals.end(); ++i, ++n){
+               if (points[i->first].first == max){
+                       points[i->first].first = n;
+               }else
+                       points[i->first].second = n;
+                       
+               if (points[i->second].first == max){
+                       points[i->second].first = n;
+               }else
+                       points[i->second].second = n;
        }
        return points;