X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FResult.java;h=7888625e1c4d898d7f431e04db9cf2bdf6c9d938;hp=cb351ebbebb0cb27fa34e2f021be4f59b7d59cae;hb=fe637b465179cf2a217bbfc76d12bc41551b4ac4;hpb=fc8cad4de7decd07e23f26ccfadb5e6d1ce291d5 diff --git a/src/edu/berkeley/sbp/Result.java b/src/edu/berkeley/sbp/Result.java index cb351eb..7888625 100644 --- a/src/edu/berkeley/sbp/Result.java +++ b/src/edu/berkeley/sbp/Result.java @@ -15,16 +15,51 @@ class Result implements GraphViz.ToGraphViz { private Node parent; private GSS.Phase phase; private Position reduction; + private HashSet children = new HashSet(); + private boolean destroyed = false; public Position reduction() { return reduction; } public GSS.Phase phase() { return phase; } public Forest getForest() { return f; } public Node parent() { return parent; } + public void addChild(Node child) { children.add(child); } + public void removeChild(Node child) { children.remove(child); } + + public boolean usedByAnyNode() { return children.size() > 0; } + public boolean usedByNonDoomedNode() { + for(Node n : children) + if (!n.state().doomed) + return true; + return false; + } + + public String toString() { return super.toString()+"->"+parent(); } + + public void check() { if (children.size()==0) destroy(); } + public void destroy() { + if (destroyed) return; + if (parent==null) return; // never destroy the "primordeal" result + destroyed = true; + if (parent() != null) { + parent().removeChild(this); + parent().check(); + } + OUTER: while(true) { + for(Node n : children) { + children.remove(n); + n.removeResult(this); + n.check(); + continue OUTER; + } + break; + } + } public Result(Forest f, Node parent, Position reduction) { this.f = f; this.reduction = reduction; this.parent = parent; + if (parent != null) parent.addChild(this); if (parent != null) phase = parent.phase(); }