[PPL-devel] [GIT] ppl/ppl(master): Improved functions and methods to build linear expressions.

Roberto Bagnara bagnara at cs.unipr.it
Sun Mar 22 19:38:36 CET 2009


Module: ppl/ppl
Branch: master
Commit: 27265c8661e2ae0daef395d8ae9fffc63102d11c
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=27265c8661e2ae0daef395d8ae9fffc63102d11c

Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date:   Sun Mar 22 19:38:01 2009 +0100

Improved functions and methods to build linear expressions.
Avoid complex inline functions and methods.

---

 src/Linear_Expression.cc         |   69 +++++++++++++++++++++++++++++++++++---
 src/Linear_Expression.inlines.hh |   59 --------------------------------
 2 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/src/Linear_Expression.cc b/src/Linear_Expression.cc
index a694a15..23b4ca1 100644
--- a/src/Linear_Expression.cc
+++ b/src/Linear_Expression.cc
@@ -77,6 +77,35 @@ PPL::Linear_Expression::Linear_Expression(const Congruence& cg)
     e[i] = cg[i];
 }
 
+PPL::Linear_Expression::Linear_Expression(const Variable v)
+  : Linear_Row(v.space_dimension() <= max_space_dimension()
+	       ? v.space_dimension() + 1
+	       : (throw std::length_error("PPL::Linear_Expression::"
+					  "Linear_Expression(v):\n"
+					  "v exceeds the maximum allowed "
+					  "space dimension."),
+		  v.space_dimension() + 1)
+	       , Linear_Row::Flags()) {
+  ++((*this)[v.space_dimension()]);
+}
+
+PPL::Linear_Expression::Linear_Expression(const Variable v, const Variable w)
+  : Linear_Row() {
+  const dimension_type v_space_dim = v.space_dimension();
+  const dimension_type w_space_dim = w.space_dimension();
+  const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
+  if (space_dim > max_space_dimension())
+    throw std::length_error("PPL::Linear_Expression::"
+                            "Linear_Expression(v, w):\n"
+                            "v or w exceed the maximum allowed "
+                            "space dimension.");
+  construct(space_dim+1, Linear_Row::Flags());
+  if (v_space_dim != w_space_dim) {
+    ++((*this)[v_space_dim]);
+    --((*this)[w_space_dim]);
+  }
+}
+
 /*! \relates Parma_Polyhedra_Library::Linear_Expression */
 PPL::Linear_Expression
 PPL::operator+(const Linear_Expression& e1, const Linear_Expression& e2) {
@@ -110,6 +139,21 @@ PPL::operator+(const Linear_Expression& e1, const Linear_Expression& e2) {
   return r;
 }
 
+/*! \relates Linear_Expression */
+PPL::Linear_Expression
+PPL::operator+(const Variable v, const Linear_Expression& e) {
+  const dimension_type v_space_dim = v.space_dimension();
+  if (v_space_dim > Linear_Expression::max_space_dimension())
+    throw std::length_error("Linear_Expression "
+                            "PPL::operator+(v, e):\n"
+                            "v exceeds the maximum allowed "
+                            "space dimension.");
+  const dimension_type space_dim = std::max(v_space_dim, e.space_dimension());
+  Linear_Expression r(e, space_dim+1);
+  ++r[v_space_dim];
+  return r;
+}
+
 /*! \relates Parma_Polyhedra_Library::Linear_Expression */
 PPL::Linear_Expression
 PPL::operator+(Coefficient_traits::const_reference n,
@@ -189,11 +233,26 @@ PPL::operator-(const Variable v, const Linear_Expression& e) {
                             "space dimension.");
   const dimension_type e_space_dim = e.space_dimension();
   const dimension_type space_dim = std::max(v_space_dim, e_space_dim);
-  Linear_Expression result(space_dim+1, false);
-  ++result[v_space_dim];
-  for (dimension_type i = e_space_dim+1; i-- > 0; )
-    result[i] -= e[i];
-  return result;
+  Linear_Expression r(e, space_dim+1);
+  for (dimension_type i = e.size(); i-- > 0; )
+    neg_assign(r[i]);
+  ++r[v_space_dim];
+  return r;
+}
+
+/*! \relates Linear_Expression */
+PPL::Linear_Expression
+PPL::operator-(const Linear_Expression& e, const Variable v) {
+  const dimension_type v_space_dim = v.space_dimension();
+  if (v_space_dim > Linear_Expression::max_space_dimension())
+    throw std::length_error("Linear_Expression "
+                            "PPL::operator-(e, v):\n"
+                            "v exceeds the maximum allowed "
+                            "space dimension.");
+  const dimension_type space_dim = std::max(v_space_dim, e.space_dimension());
+  Linear_Expression r(e, space_dim+1);
+  --r[v_space_dim];
+  return r;
 }
 
 /*! \relates Parma_Polyhedra_Library::Linear_Expression */
diff --git a/src/Linear_Expression.inlines.hh b/src/Linear_Expression.inlines.hh
index 1af543a..535fa91 100644
--- a/src/Linear_Expression.inlines.hh
+++ b/src/Linear_Expression.inlines.hh
@@ -45,37 +45,6 @@ Linear_Expression::Linear_Expression(dimension_type sz, bool)
 }
 
 inline
-Linear_Expression::Linear_Expression(const Variable v)
-  : Linear_Row(v.space_dimension() <= max_space_dimension()
-	       ? v.space_dimension() + 1
-	       : (throw std::length_error("PPL::Linear_Expression::"
-					  "Linear_Expression(v):\n"
-					  "v exceeds the maximum allowed "
-					  "space dimension."),
-		  v.space_dimension() + 1)
-	       , Linear_Row::Flags()) {
-  ++((*this)[v.space_dimension()]);
-}
-
-inline
-Linear_Expression::Linear_Expression(const Variable v, const Variable w)
-  : Linear_Row() {
-  const dimension_type v_space_dim = v.space_dimension();
-  const dimension_type w_space_dim = w.space_dimension();
-  const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
-  if (space_dim > max_space_dimension())
-    throw std::length_error("PPL::Linear_Expression::"
-                            "Linear_Expression(v, w):\n"
-                            "v or w exceed the maximum allowed "
-                            "space dimension.");
-  construct(space_dim+1, Linear_Row::Flags());
-  if (v_space_dim != w_space_dim) {
-    ++((*this)[v_space_dim]);
-    --((*this)[w_space_dim]);
-  }
-}
-
-inline
 Linear_Expression::Linear_Expression(const Linear_Expression& e)
   : Linear_Row(e) {
 }
@@ -143,20 +112,6 @@ operator+(const Linear_Expression& e, Coefficient_traits::const_reference n) {
 
 /*! \relates Linear_Expression */
 inline Linear_Expression
-operator+(const Variable v, const Linear_Expression& e) {
-  const dimension_type v_space_dim = v.space_dimension();
-  if (v_space_dim > Linear_Expression::max_space_dimension())
-    throw std::length_error("PPL::operator+(v, e):\n"
-                            "v exceeds the maximum allowed "
-                            "space dimension.");
-  const dimension_type space_dim = std::max(v_space_dim, e.space_dimension());
-  Linear_Expression result(e, space_dim+1);
-  ++result[v_space_dim];
-  return result;
-}
-
-/*! \relates Linear_Expression */
-inline Linear_Expression
 operator+(const Linear_Expression& e, const Variable v) {
   return v + e;
 }
@@ -175,20 +130,6 @@ operator-(const Variable v, const Variable w) {
 
 /*! \relates Linear_Expression */
 inline Linear_Expression
-operator-(const Linear_Expression& e, const Variable v) {
-  const dimension_type v_space_dim = v.space_dimension();
-  if (v_space_dim > Linear_Expression::max_space_dimension())
-    throw std::length_error("PPL::operator-(e, v):\n"
-                            "v exceeds the maximum allowed "
-                            "space dimension.");
-  const dimension_type space_dim = std::max(v_space_dim, e.space_dimension());
-  Linear_Expression result(e, space_dim+1);
-  --result[v_space_dim];
-  return result;
-}
-
-/*! \relates Linear_Expression */
-inline Linear_Expression
 operator*(const Linear_Expression& e, Coefficient_traits::const_reference n) {
   return n * e;
 }




More information about the PPL-devel mailing list