]> ruin.nu Git - germs.git/blobdiff - src/genealgorithms.cpp
findIntervalsAtPoitns is now O(n)
[germs.git] / src / genealgorithms.cpp
index 4315cb391e46bfad6c7d10073ee485f2962a4158..d85cd8d16caba9f60a2cefb104be7c6962729ea1 100644 (file)
@@ -116,34 +116,19 @@ std::vector<Interval> findIntervals(const GeneOrder& go){
  * 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;