change naming: use pred/succ rather than parent/child
[sbp.git] / src / edu / berkeley / sbp / Result.java
index 6054fa1..efaad4c 100644 (file)
@@ -9,53 +9,53 @@ import java.util.*;
 final class Result implements GraphViz.ToGraphViz {
 
     private Forest f;
-    private Node parent;
-    private HashSet<Node> children = new HashSet<Node>();
+    private Node pred;
+    private HashSet<Node> successors = new HashSet<Node>();
     private boolean destroyed = false;
     private int usedByNonDoomedNode = 0;
 
-    public GSS.Phase phase() { return parent==null ? null : parent.phase(); }
+    public GSS.Phase phase() { return pred==null ? null : pred.phase(); }
     public Forest getForest() { return f; }
-    public Node parent() { return parent; }
-    public void addChild(Node child) {
-        children.add(child);
-        usedByNonDoomedNode += child.state().doomed ? 0 : 1;
+    public Node pred() { return pred; }
+    public void addSucc(Node succ) {
+        successors.add(succ);
+        usedByNonDoomedNode += succ.state().doomed ? 0 : 1;
     }
-    public void removeChild(Node child) {
-        if (!children.contains(child)) return;
-        children.remove(child);
-        usedByNonDoomedNode -= child.state().doomed ? 0 : 1;
+    public void removeSucc(Node succ) {
+        if (!successors.contains(succ)) return;
+        successors.remove(succ);
+        usedByNonDoomedNode -= succ.state().doomed ? 0 : 1;
         check();
     }
 
-    public boolean usedByAnyNode() { return children.size() > 0; }
+    public boolean usedByAnyNode() { return successors.size() > 0; }
     public boolean usedByNonDoomedNode() { return usedByNonDoomedNode > 0; }
 
-    public String toString() { return super.toString()+"->"+parent(); }
+    public String toString() { return super.toString()+"->"+pred(); }
 
-    public void check() { if (children.size()==0) destroy(); }
+    public void check() { if (successors.size()==0) destroy(); }
     public void destroy() {
         if (destroyed) return;
-        if (parent==null) return;  // never destroy the "primordeal" result
+        if (pred==null) return;  // never destroy the "primordeal" result
         destroyed = true;
-        parent.removeChild(this);
-        while(children.size() > 0)
-            for(Node n : children) {
-                removeChild(n);
+        pred.removeSucc(this);
+        while(successors.size() > 0)
+            for(Node n : successors) {
+                removeSucc(n);
                 n.removeResult(this);
                 break;
             }
     }
 
-    public Result(Forest f, Node parent, Pos reduction) {
-        this(f, parent, reduction, null);
+    public Result(Forest f, Node pred, Pos reduction) {
+        this(f, pred, reduction, null);
     }
-    public Result(Forest f, Node parent, Pos reduction, GSS.Phase target) {
+    public Result(Forest f, Node pred, Pos reduction, GSS.Phase target) {
         this.f = f;
-        this.parent = parent;
-        if (parent != null) parent.addChild(this);
+        this.pred = pred;
+        if (pred != null) pred.addSucc(this);
         if (reduction == null) return;
-        Parser.Table.State state0 = (Parser.Table.State)parent.state().gotoSetNonTerminals.get(reduction);
+        Parser.Table.State state0 = (Parser.Table.State)pred.state().gotoSetNonTerminals.get(reduction);
         target.newNodeFromReduction(this, state0, reduction);
     }
 
@@ -66,7 +66,7 @@ final class Result implements GraphViz.ToGraphViz {
         GraphViz.Node n = gv.createNode(this);
         n.label = ""+f;
         n.shape = "rectangle";
-        if (parent()!=null) n.edge(parent, "");
+        if (pred()!=null) n.edge(pred, "");
         n.color = "blue";
         if (phase() != null)
             ((GraphViz.Group)phase().toGraphViz(gv)).add(n);