changes
authorbdemsky <bdemsky>
Sat, 17 Oct 2009 21:56:43 +0000 (21:56 +0000)
committerbdemsky <bdemsky>
Sat, 17 Oct 2009 21:56:43 +0000 (21:56 +0000)
Robust/src/Benchmarks/SingleTM/Yada/avltree.java
Robust/src/Benchmarks/SingleTM/Yada/edge.java
Robust/src/Benchmarks/SingleTM/Yada/element.java
Robust/src/Benchmarks/SingleTM/Yada/makefile
Robust/src/Benchmarks/SingleTM/Yada/mesh.java

index 7efece87b564eee8e5ffdf3124103416a03ec86d..780265fa5748cadd14e9965e5a8855a66c252eab 100644 (file)
 
 /* Rebalance after insertion */
 #define jsw_insert_balance(root,dir) do {  \
-  avlnode n = root.link[dir];      \
+  avlnode ni = root.link[dir];      \
   int bal = dir == 0 ? -1 : +1;          \
-  if ( n.balance == bal ) {               \
-    root.balance = n.balance = 0;        \
+  if ( ni.balance == bal ) {               \
+    root.balance = ni.balance = 0;        \
     jsw_single ( root, 1-dir );             \
   }                                        \
   else { /* n.balance == -bal */          \
 
 /* Rebalance after deletion */
 #define jsw_remove_balance(root,dir,done) do { \
-  avlnode n = root.link[1-dir];         \
+  avlnode nr = root.link[1-dir];         \
   int bal = dir == 0 ? -1 : +1;              \
-  if ( n.balance == -bal ) {                  \
-    root.balance = n.balance = 0;            \
+  if ( nr.balance == -bal ) {               \
+    root.balance = nr.balance = 0;            \
     jsw_single ( root, dir );                  \
   }                                            \
-  else if ( n.balance == bal ) {              \
+  else if ( nr.balance == bal ) {              \
     jsw_adjust_balance ( root, 1-dir, -bal );   \
     jsw_double ( root, dir );                  \
   }                                            \
   else { /* n.balance == 0 */                 \
     root.balance = -bal;                      \
-    n.balance = bal;                          \
+    nr.balance = bal;                         \
     jsw_single ( root, dir );                  \
     done = 1;                                  \
   }                                            \
@@ -276,7 +276,7 @@ public class avltree {
   boolean avlinsert(Object data ) {
     /* Empty tree case */
     if ( root == null ) {
-      root = new avlnode(tree,data);
+      root = new avlnode(this,data);
     } else {
       avlnode head =new avlnode(); /* Temporary tree root */
       avlnode s, t;     /* Place to rebalance and parent */
@@ -301,7 +301,7 @@ public class avltree {
        }
       }
       
-      p.link[dir] = q = new avlnode(tree, data);
+      p.link[dir] = q = new avlnode(this, data);
       if (q==null)
        return false;
       
@@ -349,7 +349,7 @@ public class avltree {
          break;
        
        /* Push direction and node onto stack */
-       upd[top] = cmp ( it.data, data ) < 0;
+       upd[top] = (cmp ( it.data, data ) < 0)?1:0;
        up[top++] = it;
        
        it = it.link[upd[top - 1]];
@@ -364,7 +364,7 @@ public class avltree {
        if (top != 0)
          up[top-1].link[upd[top - 1]] = it.link[dir];
        else
-         tree.root = it.link[dir];
+         root = it.link[dir];
       } else {
        /* Find the inorder successor */
        avlnode heir = it.link[1];
@@ -385,7 +385,7 @@ public class avltree {
        heir.data = save;
 
        /* Unlink successor and fix parent */
-       up[top-1].link[up[top - 1] == it] = heir.link[1];
+       up[top-1].link[(up[top - 1] == it)?1:0] = heir.link[1];
     }
 
       /* Walk back up the search path */
@@ -394,9 +394,9 @@ public class avltree {
        up[top].balance += upd[top] != 0 ? -1 : +1;
        
        /* Terminate or rebalance as necessary */
-       if ( abs ( up[top].balance ) == 1 )
+       if (up[top].balance == 1 || up[top].balance==-1 )
          break;
-       else if ( abs ( up[top].balance ) > 1 ) {
+       else if ( up[top].balance > 1 ||up[top].balance < -1) {
          jsw_remove_balance ( up[top], upd[top], done );
          
          /* Fix parent */
index 65359c3cfa9a244413323ade60ed09bd4c50923f..709a51928a4c6cac77e711bc8d4d3bbc044fb646 100644 (file)
 import java.util.*;
 
 public class edge {
-  public Object first;
-  public Object second;
+  public Object firstPtr;
+  public Object secondPtr;
   
   public edge() {
-    first = null;
-    second = null;
+    firstPtr = null;
+    secondPtr = null;
   }
   
 
@@ -91,8 +91,8 @@ public class edge {
    * =============================================================================
    */
   public edge(Object first,Object second) {
-    this.first = first;
-    this.second = second;
+    this.firstPtr = first;
+    this.secondPtr = second;
   }
 
 
@@ -103,9 +103,9 @@ public class edge {
    * void pair_swap (pair_t* pairPtr);
    */
   public void swap() {
-    Object tmpPtr = first;
-    first=second;
-    second=tmpPtr;
+    Object tmpPtr = firstPtr;
+    firstPtr=secondPtr;
+    secondPtr=tmpPtr;
   }
 }    
 
index 5f2c0ea5f0424ef359b3ba3a2782eab27fe92256..5057f7eb1aae8245db38748517b9da65721a7194 100644 (file)
@@ -97,7 +97,7 @@ public class element {
     int minPosition = 0;
 
     for (int i = 1; i < numCoordinate; i++) {
-      if (coordinate_compare(coordinates[i], coordinates[minPosition]) < 0) {
+      if (coordinate.coordinate_compare(coordinates[i], coordinates[minPosition]) < 0) {
        minPosition = i;
       }
     }
@@ -130,7 +130,7 @@ public class element {
     if (numCoordinate == 3) {
         int i;
         for (i = 0; i < 3; i++) {
-         double angle = coordinate_angle(coordinates[i],
+         double angle = coordinate.coordinate_angle(coordinates[i],
                                          coordinates[(i + 1) % 3],
                                          coordinates[(i + 2) % 3]);
          yada.Assert(angle > 0.0);
@@ -212,7 +212,7 @@ public class element {
       circumCenterPtr.y = ry;
     }
 
-    elementPtr.circumRadius = coordinate_distance(circumCenterPtr,
+    elementPtr.circumRadius = coordinate.coordinate_distance(circumCenterPtr,
                                                  coordinates[0]);
   }
 
@@ -228,7 +228,7 @@ public class element {
     coordinate secondPtr = coordinates[(i + 1) % numCoordinate];
     
     edge edgePtr = edges[i];
-    int cmp = coordinate_compare(firstPtr, secondPtr);
+    int cmp = coordinate.coordinate_compare(firstPtr, secondPtr);
     yada.Assert(cmp != 0);
     if (cmp < 0) {
       edgePtr.firstPtr  = firstPtr;
@@ -242,7 +242,7 @@ public class element {
     midpointPtr.x = (firstPtr.x + secondPtr.x) / 2.0;
     midpointPtr.y = (firstPtr.y + secondPtr.y) / 2.0;
 
-    elementPtr.radii[i] = coordinate_distance(firstPtr, midpointPtr);
+    elementPtr.radii[i] = coordinate.coordinate_distance(firstPtr, midpointPtr);
   }
 
 
@@ -266,8 +266,8 @@ public class element {
 int element_compare (element aElementPtr, element bElementPtr) {
   int aNumCoordinate = aElementPtr.numCoordinate;
   int bNumCoordinate = bElementPtr.numCoordinate;
-  coordinate aCoordinates = aElementPtr.coordinates;
-  coordinate bCoordinates = bElementPtr.coordinates;
+  coordinate aCoordinates[] = aElementPtr.coordinates;
+  coordinate bCoordinates[] = bElementPtr.coordinates;
 
   if (aNumCoordinate < bNumCoordinate) {
     return -1;
@@ -277,7 +277,7 @@ int element_compare (element aElementPtr, element bElementPtr) {
 
   for (int i = 0; i < aNumCoordinate; i++) {
     int compareCoordinate =
-      coordinate_compare(aCoordinates[i], bCoordinates[i]);
+      coordinate.coordinate_compare(aCoordinates[i], bCoordinates[i]);
     if (compareCoordinate != 0) {
       return compareCoordinate;
     }
@@ -368,12 +368,12 @@ int element_compare (element aElementPtr, element bElementPtr) {
  * =============================================================================
  */
   static int compareEdge(edge aEdgePtr, edge bEdgePtr) {
-    int diffFirst = coordinate_compare((coordinate)aEdgePtr.firstPtr,
+    int diffFirst = coordinate.coordinate_compare((coordinate)aEdgePtr.firstPtr,
                                         (coordinate)bEdgePtr.firstPtr);
 
     return ((diffFirst != 0) ?
             (diffFirst) :
-            (coordinate_compare((coordinate)aEdgePtr.secondPtr,
+            (coordinate.coordinate_compare((coordinate)aEdgePtr.secondPtr,
                                 (coordinate)bEdgePtr.secondPtr)));
   }
 
@@ -416,15 +416,15 @@ int element_compare (element aElementPtr, element bElementPtr) {
     element aElementPtr = (element)aPtr;
     element bElementPtr = (element)bPtr;
    
-    if (aElementPtr.encroachedEdgePtr) {
-      if (bElementPtr.encroachedEdgePtr) {
+    if (aElementPtr.encroachedEdgePtr!=null) {
+      if (bElementPtr.encroachedEdgePtr!=null) {
        return 0; /* do not care */
       } else {
        return 1;
       }
     }
     
-    if (bElementPtr.encroachedEdgePtr) {
+    if (bElementPtr.encroachedEdgePtr!=null) {
       return -1;
     }
     
@@ -437,7 +437,7 @@ int element_compare (element aElementPtr, element bElementPtr) {
  * =============================================================================
  */
   boolean element_isInCircumCircle(coordinate coordinatePtr) {
-    double distance = coordinate_distance(coordinatePtr, circumCenter);
+    double distance = coordinate.coordinate_distance(coordinatePtr, circumCenter);
     return distance <= circumRadius;
   }
 
@@ -538,7 +538,7 @@ int element_compare (element aElementPtr, element bElementPtr) {
  * =============================================================================
  */
   void element_addNeighbor(element neighborPtr) {
-    TMLIST_INSERT(neighborListPtr, neighborPtr);
+    neighborListPtr.insert(neighborPtr);
   }
 
 
@@ -605,7 +605,7 @@ int element_compare (element aElementPtr, element bElementPtr) {
     //    double angleConstraint = global_angleConstraint;
     if (numCoordinate == 3) {
       for (int i = 0; i < 3; i++) {
-       double angle = coordinate_angle(coordinates[i],
+       double angle = coordinate.coordinate_angle(coordinates[i],
                                        coordinates[(i + 1) % 3],
                                        coordinates[(i + 2) % 3]);
        if (angle < angleConstraint) {
@@ -623,7 +623,7 @@ int element_compare (element aElementPtr, element bElementPtr) {
  */
   void element_print() {
     for (int c = 0; c < numCoordinate; c++) {
-      coordinate_print(coordinates[c]);
+      coordinates[c].coordinate_print();
       System.out.println(" ");
     }
   }
@@ -634,9 +634,9 @@ int element_compare (element aElementPtr, element bElementPtr) {
  * =============================================================================
  */
   void element_printEdge (edge edgePtr) {
-    coordinate_print((coordinate)edgePtr.firstPtr);
+    ((coordinate)edgePtr.firstPtr).coordinate_print();
     System.out.println(" -> ");
-    coordinate_print((coordinate)edgePtr.secondPtr);
+    ((coordinate)edgePtr.secondPtr).coordinate_print();
   }
 
 
@@ -647,7 +647,7 @@ int element_compare (element aElementPtr, element bElementPtr) {
   void element_printAngles() {
     if (numCoordinate == 3) {
       for (int i = 0; i < 3; i++) {
-       double angle = coordinate_angle(coordinates[i],
+       double angle = coordinate.coordinate_angle(coordinates[i],
                                        coordinates[(i + 1) % 3],
                                        coordinates[(i + 2) % 3]);
        System.out.println(angle);
index 71e04161b35d1195ac6b72ace2e56663448e699f..bd1fcfd2fa0d663c220e6dfb3429de1e27c0c9f4 100644 (file)
@@ -2,6 +2,7 @@ MAINCLASS=yada
 SRC=${MAINCLASS}.java \
        tmpheap.java \
        List_t.java \
+       tmpRBTree.java \
        Random.java  \
        tmpQueue_t.java  \
        coordinate.java  \
@@ -21,7 +22,7 @@ prep:
        cpp -P heap.java > tmpheap.java
        cpp -P avltree.java > tmpavltree.java
        cpp -P Queue_t.java > tmpQueue_t.java
-
+       cpp -P RBTree.java > tmpRBTree.java
 clean:
        rm tmp*.java
        rm ttt*.java
index d2c41ef4b0e93bddf57d777193b079f2493345b2..288154d408c24a8a4257dd94d153937911255515 100644 (file)
@@ -72,7 +72,7 @@ public class mesh {
     element rootElementPtr;
     Queue_t initBadQueuePtr;
     int size;
-    SET_T boundarySetPtr;
+    RBTree boundarySetPtr;
 
 /* =============================================================================
  * mesh_alloc
@@ -82,7 +82,7 @@ public class mesh {
     rootElementPtr = null;
     initBadQueuePtr = new Queue_t(-1);
     size = 0;
-    boundarySetPtr = SET_ALLOC(null, element_listCompareEdge);
+    boundarySetPtr = new RBTree(null, element_listCompareEdge);
   }
 
 
@@ -135,7 +135,7 @@ public class mesh {
   
   edge encroachedPtr = elementPtr.element_getEncroachedPtr();
   if (encroachedPtr!=null) {
-    if (!TMSET_CONTAINS(meshPtr.boundarySetPtr, encroachedPtr)) {
+    if (!boundarySetPtr.contains(encroachedPtr)) {
       element_clearEncroached(elementPtr);
     }
   }
@@ -179,7 +179,7 @@ public void TMmesh_remove(element elementPtr) {
  * =============================================================================
  */
 boolean TMmesh_insertBoundary(edge boundaryPtr) {
-  return TMSET_INSERT(boundarySetPtr, boundaryPtr);
+  return boundarySetPtr.insert(boundaryPtr,null);
 }
 
 
@@ -188,7 +188,7 @@ boolean TMmesh_insertBoundary(edge boundaryPtr) {
  * =============================================================================
  */
 boolean TMmesh_removeBoundary(edge boundaryPtr) {
-  return TMSET_REMOVE(boundarySetPtr, boundaryPtr);
+  return boundarySetPtr.remove(boundaryPtr);
 }
 
 
@@ -204,7 +204,7 @@ static void createElement (coordinate coordinates,
 
     if (numCoordinate == 2) {
         edge boundaryPtr = elementPtr.element_getEdge(0);
-        boolean status = SET_INSERT(boundarySetPtr, boundaryPtr);
+        boolean status = boundarySetPtr.insert(boundaryPtr, null);
         yada.Assert(status);
     }