From: Michael Andreen Date: Wed, 20 Jun 2007 06:57:56 +0000 (+0000) Subject: moved a function and added comment X-Git-Tag: v0.1~61 X-Git-Url: https://ruin.nu/git/?p=germs.git;a=commitdiff_plain;h=500fc81f4ccf04414ebbd495d167eb2d6b2ac82d moved a function and added comment --- diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 04875da..24e7b43 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -65,40 +65,6 @@ struct FindP{ }; -std::vector findIntervalsAtPoints(const vector& intervals){ - vector 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::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)); - } - return points; - -} - int countCycles(const GeneOrder& go){ int cycles = 0; set marked; @@ -163,3 +129,40 @@ std::vector findIntervals(const GeneOrder& go){ return intervals; } +/** + * TODO: Think of a better than O(n^2) implementation. + * Possibly move to cache result + */ +std::vector findIntervalsAtPoints(const vector& intervals){ + vector 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::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)); + } + return points; + +}