X-Git-Url: https://ruin.nu/git/?p=germs.git;a=blobdiff_plain;f=src%2Fgenealgorithms.cpp;h=eecdf3fea92bd8048c6c47fd1ef466d5e4698c67;hp=7dc832f252c208900b92c234879c8f09b5a93c24;hb=6be4116d6211ac4ba4c68dc2ab28f1bc5d77068e;hpb=e7953f0050007cd1999d64d985d0a063b9ddc99b diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 7dc832f..eecdf3f 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace std; std::pair longestSequences(const GeneOrder& go){ @@ -69,6 +70,33 @@ std::vector findComponents(const GeneOrder& go){ return vector(); } +//TODO: Think of a better than O(n^2) implementation std::vector findIntervals(const GeneOrder& go){ - return vector(); + vector intervals; + for (size_t i = 0; i < go.size() - 1; ++i){ + size_t f = 0; + size_t s = 0; + bool found = false; + size_t n = 0; + for (GeneOrder::iterator g = go.begin(); g != go.end(); ++g, ++n){ + if (static_cast(abs(*g)) == i){ + f = n; + if (*g >= 0) + ++f; + if (found) + break; + found = true; + } + if(static_cast(abs(*g)) == i+1){ + s = n; + if (*g < 0) + ++s; + if (found) + break; + found = true; + } + } + intervals.push_back(Interval(f,s)); + } + return intervals; }