Tried to squeeze out more performance by changing the LinkedLIsts in the Delaunay...
authorstephey <stephey>
Thu, 31 Mar 2011 09:04:04 +0000 (09:04 +0000)
committerstephey <stephey>
Thu, 31 Mar 2011 09:04:04 +0000 (09:04 +0000)
Added Vector.clone() and VectorIterator

Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java
Robust/src/Benchmarks/oooJava/DelaunayRefinement/runs
Robust/src/ClassLibrary/Vector.java
Robust/src/ClassLibrary/VectorIterator.java [new file with mode: 0644]

index e8719acd11a044645fc7a9ea3027712913547b46..a37fba5a5344de800679e0c444737b542c281c34 100644 (file)
@@ -29,7 +29,7 @@ public class DirectedGraph implements Graph {
   public Iterator getInNeighbors(Node src) {
     GraphNode src_c = (GraphNode) src;
     // return Collections.unmodifiableCollection(src_c.getInNeighbors());
-    return src_c.getInNeighborsCopy();
+    return src_c.getInNeighborsCopy().iterator();
   }
 
   public int getInNeighborsSize(Node node) {
@@ -43,7 +43,7 @@ public class DirectedGraph implements Graph {
   public Iterator getOutNeighbors(Node src) {
     GraphNode src_c = (GraphNode) src;
     // return Collections.unmodifiableCollection(src_c.getOutNeighbors());
-    return src_c.getOutNeighborsCopy();
+    return src_c.getOutNeighborsCopy().iterator();
   }
 
   public int getOutNeighborsSize(Node node) {
@@ -73,11 +73,12 @@ public class DirectedGraph implements Graph {
 
   protected void removeConnectingEdges(GraphNode n) {
     GraphNode g;
-    for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext(); removeNeighbor(n, g)) {
+
+    for (Iterator iterator1 = n.getOutNeighborsCopy().iterator(); iterator1.hasNext(); removeNeighbor(n, g)) {
       g = (GraphNode) iterator1.next();
     }
-
-    for (Iterator iterator2 = n.getInNeighborsCopy(); iterator2.hasNext(); removeNeighbor(g, n)) {
+    
+    for (Iterator iterator2 = n.getInNeighborsCopy().iterator(); iterator2.hasNext(); removeNeighbor(g, n)) {
       g = (GraphNode) iterator2.next();
     }
 
index e82317791f2572fd9086a9926edb461098517d4a..755d453403ecc3c06aec0300075b0de058c755fd 100644 (file)
@@ -2,8 +2,8 @@ public class GraphNode extends Node {
   protected Object data;
   // protected List inNeighbors;
   // protected List outNeighbors;
-  protected LinkedList inNeighbors;
-  protected LinkedList outNeighbors;
+  protected Vector inNeighbors;
+  protected Vector outNeighbors;
 
   protected GraphNode() {
     super();
@@ -12,8 +12,8 @@ public class GraphNode extends Node {
   public GraphNode(Object n) {
     super();
     data = n;
-    inNeighbors = new LinkedList();
-    outNeighbors = new LinkedList();
+    inNeighbors = new Vector();
+    outNeighbors = new Vector();
   }
 
 //  public Object getData() {
@@ -28,7 +28,7 @@ public class GraphNode extends Node {
     if (inNeighbors.contains(n)) {
       return false;
     } else {
-      inNeighbors.addLast(n);
+      inNeighbors.addElement(n);
       return true;
     }
   }
@@ -41,24 +41,19 @@ public class GraphNode extends Node {
     return inNeighbors.contains(n);
   }
 
-  public final Iterator getInNeighbors() {
-    return inNeighbors.iterator();
+  public final Vector getInNeighbors() {
+    return inNeighbors;
   }
 
-  public final Iterator getInNeighborsCopy() {
-    LinkedList l = new LinkedList();
-    Iterator o = inNeighbors.iterator();
-    while (o.hasNext()) {
-      l.addLast(o);
-    }
-    return l.iterator();
+  public final Vector getInNeighborsCopy() {
+    return inNeighbors.clone();
   }
 
   public final boolean addOutNeighbor(GraphNode n) {
     if (outNeighbors.contains(n)) {
       return false;
     } else {
-      outNeighbors.addLast(n);
+      outNeighbors.addElement(n);
       return true;
     }
   }
@@ -66,21 +61,15 @@ public class GraphNode extends Node {
   public final boolean removeOutNeighbor(GraphNode n) {
     return outNeighbors.remove(n);
   }
-
   public final boolean hasOutNeighbor(GraphNode n) {
     return outNeighbors.contains(n);
   }
 
-  public final Iterator getOutNeighbors() {
-    return outNeighbors.iterator();
+  public final Vector getOutNeighbors() {
+    return outNeighbors;
   }
 
-  public final Iterator getOutNeighborsCopy() {
-    LinkedList l = new LinkedList();
-    Iterator o = outNeighbors.iterator();
-    while (o.hasNext()) {
-      l.addLast(o);
-    }
-    return l.iterator();
+  public final Vector getOutNeighborsCopy() {
+    return outNeighbors.clone();
   }
 }
\ No newline at end of file
index 9af7cd31604f8889a7889422476d09b70c1bce6a..d2d26484da905955b770e7898bbce15795ef1bdb 100644 (file)
@@ -131,8 +131,9 @@ public class Mesh {
       if (!found.contains(node)) {
         found.add(node);
         Node neighbor;
-        for (Iterator iterator1 = mesh.getOutNeighbors(node); iterator1.hasNext(); remaining
-            .push(neighbor))
+        
+        
+        for (Iterator iterator1 = mesh.getOutNeighbors(node); iterator1.hasNext(); remaining.push(neighbor))
           neighbor = (Node) iterator1.next();
 
       }
index 344f30389389896f0cca43c76213bd13bd2802d0..d67103c8eaa7661516ead0fa3913e899ce158f45 100644 (file)
@@ -44,6 +44,7 @@ public class SerialDelaunayRefinement {
       if (runtime < mintime) {
         mintime = runtime;
       }
+      System.gc();
     }
 
     System.out.println("minimum runtime: " + mintime + " ms");
@@ -91,7 +92,6 @@ public class SerialDelaunayRefinement {
     }
 
     System.gc();
-    System.out.println("Done with GC");
 
 //    long id = Time.getNewTimeId();
     long startTime = System.currentTimeMillis();
index 9a0c9345576b87028e45f85334bf5bfd66bf0da5..f9aa7ac981b62d83b503822a1772427042a64c00 100755 (executable)
@@ -1 +1 @@
-./SerialDelaunayRefinements.bin ./input/large.2 true
+./SerialDelaunayRefinements.bin ./input/massive.2 true
index 42ab24f9f60f1147bcc4680f78e4ada828a2d8b5..884f2a6b364b90a2f2cea8184aeb4c9fbdc4c870 100644 (file)
@@ -14,6 +14,18 @@ public class Vector {
     this.size=0;
     array=new Object[size];
   }
+  
+  //used for internal cloning
+  private Vector(int size, int capacityIncrement, Object[] array) {
+    this.size = size;
+    this.capacityIncrement = capacityIncrement;
+    this.array = new Object[array.length];
+    System.arraycopy(array, 0, this.array, 0, size);
+  }
+  
+  public Vector clone() {
+    return new Vector(size,capacityIncrement, array);
+  }
 
   public boolean isEmpty() {
     return size==0;
@@ -40,10 +52,14 @@ public class Vector {
     return indexOf(e)!=-1;
   }
 
-  public void remove(Object o) {
+  public boolean  remove(Object o) {
     int in=indexOf(o);
-    if (in!=-1)
+    if (in!=-1) {
       removeElementAt(in);
+      return true;
+    }
+    
+    return false;
   }
 
   public Object elementAt(int index) {
diff --git a/Robust/src/ClassLibrary/VectorIterator.java b/Robust/src/ClassLibrary/VectorIterator.java
new file mode 100644 (file)
index 0000000..2b63930
--- /dev/null
@@ -0,0 +1,36 @@
+public class VectorIterator extends Iterator {
+  private int pos;
+  private int size;
+  private Vector list;
+
+  public VectorIterator(Vector v) {
+    this.list = v;
+    this.pos = 0;
+    this.size = this.list.size();
+  }
+
+  /**
+   * Tests to see if there are any more objects to
+   * return.
+   *
+   * @return True if the end of the list has not yet been
+   *         reached.
+   */
+  public boolean hasNext()
+  {
+    return pos < size;
+  }
+
+  /**
+   * Retrieves the next object from the list.
+   *
+   * @return The next object.
+   */
+  public Object next()
+  {
+    if (pos == size) {
+      return null;  //since we can't throw anything...
+    }
+    return this.list.get(pos++);
+  }
+}
\ No newline at end of file