From 6be4116d6211ac4ba4c68dc2ab28f1bc5d77068e Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 19 Jun 2007 09:18:53 +0000 Subject: [PATCH] findIntervals implemented and passing test --- src/genealgorithms.cpp | 30 +++++++++++++++++++++++++++++- src/test/genealgorithmstest.cpp | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) 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; } diff --git a/src/test/genealgorithmstest.cpp b/src/test/genealgorithmstest.cpp index 50a5c73..2b9ae79 100644 --- a/src/test/genealgorithmstest.cpp +++ b/src/test/genealgorithmstest.cpp @@ -89,7 +89,7 @@ protected: CPPUNIT_ASSERT(go12 == v[2]); GeneOrder go2(_validPerm2.begin(),_validPerm2.end()); - v = findIntervals(go); + v = findIntervals(go2); CPPUNIT_ASSERT_EQUAL(9ul,v.size()); Interval go20(1,3); Interval go22(1,4); -- 2.39.2