1 // Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.util.*;
5 import edu.berkeley.sbp.Sequence.Position;
8 final class Result implements GraphViz.ToGraphViz {
12 private GSS.Phase phase;
13 private Position reduction;
14 private HashSet<Node> children = new HashSet<Node>();
15 private boolean destroyed = false;
16 private int usedByNonDoomedNode = 0;
18 public Position reduction() { return reduction; }
19 public GSS.Phase phase() { return phase; }
20 public Forest getForest() { return f; }
21 public Node parent() { return parent; }
22 public void addChild(Node child) {
24 usedByNonDoomedNode += child.state().doomed ? 0 : 1;
26 public void removeChild(Node child) {
27 children.remove(child);
28 usedByNonDoomedNode -= child.state().doomed ? 0 : 1;
31 public boolean usedByAnyNode() { return children.size() > 0; }
32 public boolean usedByNonDoomedNode() { return usedByNonDoomedNode > 0; }
34 public String toString() { return super.toString()+"->"+parent(); }
36 public void check() { if (children.size()==0) destroy(); }
37 public void destroy() {
38 if (destroyed) return;
39 if (parent==null) return; // never destroy the "primordeal" result
41 if (parent() != null) {
42 parent().removeChild(this);
46 for(Node n : children) {
56 public Result(Forest f, Node parent, Position reduction) {
58 this.reduction = reduction;
60 if (parent != null) parent.addChild(this);
61 if (parent != null) phase = parent.phase();
64 // GraphViz //////////////////////////////////////////////////////////////////////////////
66 public GraphViz.Node toGraphViz(GraphViz gv) {
67 if (gv.hasNode(this)) return gv.createNode(this);
68 GraphViz.Node n = gv.createNode(this);
70 n.shape = "rectangle";
71 if (parent()!=null) n.edge(parent, "");
74 ((GraphViz.Group)phase().toGraphViz(gv)).add(n);
77 public boolean isTransparent() { return false; }
78 public boolean isHidden() { return false; }