]> ruin.nu Git - germs.git/blobdiff - src/reverseaction.h
a little performance tuning
[germs.git] / src / reverseaction.h
index 0d8ac91999e02d3f5bf2b3d1058854e3dcb76fb9..006c9eb4de9df4446b27ccaee6da4068d435a4a2 100644 (file)
 #define __REVERSEACTION_H__
 
 #include "sortaction.h"
+#include "genealgorithms.h"
+
+#include <algorithm>
+#include <sstream>
+
 /**
  * Reverses an interval
  *
@@ -33,7 +38,12 @@ class ReverseAction : public SortAction{
                /**
                 * Creates a new reverse action for the interval [i,j]
                 */
-               ReverseAction(size_t i, size_t j):_i(i),_j(j){}
+               ReverseAction(size_t i, size_t j): SortAction(0),_i(i),_j(j){
+               }
+               ReverseAction(Interval i): SortAction(0){
+                       _i = std::min(i.first,i.second);
+                       _j = std::max(i.first,i.second)-1;
+               }
 
                /**
                 * Applies the sort action on the gene order
@@ -50,6 +60,15 @@ class ReverseAction : public SortAction{
                        }
                        return false;
                }
+
+               /**
+                * Gives a string representation of the action, for output
+                */
+               virtual std::string toString() const{
+                       std::ostringstream os;
+                       os << "[" << _i << "," << _j << "]";
+                       return os.str();
+               }
        private:
                size_t _i;
                size_t _j;