[mathicgb] 278/393: Reduced code size for comparison in MonoMonoid.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:19 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.

commit acb1d8d1e7c4c48c4f6813831abc32c42a691942
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Wed Apr 17 17:24:57 2013 -0400

    Reduced code size for comparison in MonoMonoid.
---
 src/mathicgb/MonoMonoid.hpp | 63 +++++++++++++++++++++++++++++++--------------
 1 file changed, 44 insertions(+), 19 deletions(-)

diff --git a/src/mathicgb/MonoMonoid.hpp b/src/mathicgb/MonoMonoid.hpp
index bf56529..9899a79 100755
--- a/src/mathicgb/MonoMonoid.hpp
+++ b/src/mathicgb/MonoMonoid.hpp
@@ -540,17 +540,28 @@ public:
     MATHICGB_ASSERT(debugOrderValid(a));
     MATHICGB_ASSERT(debugOrderValid(b));
 
-    // todo: fold this into the lower loop if StoreOrder is true.
-    auto grading = gradingCount();
-    while (grading != 0) {
-      --grading;
-      const auto cmp = degree(a, grading) - degree(b, grading);
-      if (cmp < 0) return mLexBaseOrder ? LessThan : GreaterThan;
-      if (cmp > 0) return mLexBaseOrder ? GreaterThan : LessThan;
+    VarIndex index;
+    
+    if (StoreOrder)
+      index = orderIndexEnd();
+    else {
+      // Check the degrees seperately since they are not stored.
+      auto grading = gradingCount();
+      while (grading != 0) {
+        --grading;
+        const auto cmp = degree(a, grading) - degree(b, grading);
+        if (cmp < 0) return mLexBaseOrder ? LessThan : GreaterThan;
+        if (cmp > 0) return mLexBaseOrder ? GreaterThan : LessThan;
+      }
+      index = exponentsIndexEnd();
     }
 
-    for (auto i = exponentsIndexEnd() - 1; i != beforeEntriesIndexBegin(); --i) {
-      const auto cmp = access(a, i) - access(b, i);
+    // If StoreOrder is true then this first checks the degrees.
+    // Then the exponents are checked.
+    // Finally, if HasComponent is true, the component is checked.
+    while (index != entriesIndexBegin()) {
+      --index;
+      const auto cmp = access(a, index) - access(b, index);
       if (cmp < 0) return mLexBaseOrder ? LessThan : GreaterThan;
       if (cmp > 0) return mLexBaseOrder ? GreaterThan : LessThan;
     }
@@ -558,23 +569,37 @@ public:
   }
 
   /// Compares a to b1*b2.
-  /// @todo: test. Also, is this method necessary and useful?
+  /// @todo: Test this method. Also, is this method actually useful, or could
+  /// it just as well be replaced by a multiplication and a comparison?
   CompareResult compare(ConstMonoRef a, ConstMonoRef b1, ConstMonoRef b2) const {
     MATHICGB_ASSERT(debugOrderValid(a));
     MATHICGB_ASSERT(debugOrderValid(b1));
     MATHICGB_ASSERT(debugOrderValid(b2));
 
-    // todo: fold this into the lower loop if StoreOrder is true.
-    auto grading = gradingCount();
-    while (grading != 0) {
-      --grading;
-      const auto cmp = degree(a, grading) - (degree(b1, grading) + degree(b2, grading));
-      if (cmp < 0) return mLexBaseOrder ? LessThan : GreaterThan;
-      if (cmp > 0) return mLexBaseOrder ? GreaterThan : LessThan;
+    VarIndex index;
+
+    if (StoreOrder)
+      index = orderIndexEnd();
+    else {
+      // Check the degrees seperately since they are not stored.
+      auto grading = gradingCount();
+      while (grading != 0) {
+        --grading;
+        const auto cmp =
+          degree(a, grading) - (degree(b1, grading) + degree(b2, grading));
+        if (cmp < 0) return mLexBaseOrder ? LessThan : GreaterThan;
+        if (cmp > 0) return mLexBaseOrder ? GreaterThan : LessThan;
+      }
+      index = exponentsIndexEnd();
     }
 
-    for (auto i = exponentsIndexEnd() - 1; i != beforeEntriesIndexBegin(); --i) {
-      const auto cmp = access(a, i) - (access(b1, i) + access(b2, i));
+    // If StoreOrder is true then this first checks the degrees.
+    // Then the exponents are checked.
+    // Finally, if HasComponent is true, the component is checked.
+    while (index != entriesIndexBegin()) {
+      --index;
+      const auto cmp =
+        access(a, index) - (access(b1, index) + access(b2, index));
       if (cmp < 0) return mLexBaseOrder ? LessThan : GreaterThan;
       if (cmp > 0) return mLexBaseOrder ? GreaterThan : LessThan;
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git



More information about the debian-science-commits mailing list