fix bitvector compare according to lexicographic order, length is secondary
authorYanhuaSun <sun51@illinois.edu>
Fri, 11 Oct 2013 14:02:13 +0000 (09:02 -0500)
committerYanhuaSun <sun51@illinois.edu>
Fri, 11 Oct 2013 14:02:13 +0000 (09:02 -0500)
src/util/ckbitvector.C

index bc84afa893707c199751e4d7faebd600ea561d74..d81f7447e5d4cb7fbba80f363e4296659a6aca31 100644 (file)
@@ -416,22 +416,31 @@ int CkBitVector::Compare(const CkBitVector &b) const
     int result = 0;
     int length, i;
     if(usedBits > b.usedBits)
+    {
         result = 1;
+        length = chunks(b.usedBits);
+    }
     else if (usedBits < b.usedBits)
+    {
         result = -1;
-    else {
         length = chunks(usedBits);
-        for(i=0; i<length; i++)
+    }
+    else
+    {
+        result = 0;
+        length = chunks(usedBits);
+    }
+
+    for(i=length; i>=0; i--)
+    {
+        if(data[i] > b.data[i])
+        {
+            result = 1;
+            break;
+        }else if (data[i] < b.data[i])
         {
-            if(data[i] > b.data[i])
-            {
-                result = 1;
-                break;
-            }else if (data[i] < b.data[i])
-            {
-                result = -1;
-                break;
-            }
+            result = -1;
+            break;
         }
     }
     return result;