+ 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;
+ }
+ }