- public boolean merge(Result r) {
- if (results.contains(r)) return true;
- results.add(r);
- if (fromEmptyReduction) return false;
- state.invokeReductions(phase().getToken(), this, false, r);
- return false;
+ boolean destroyed = false;
+
+ public void check() {
+ if (destroyed) return;
+ boolean dead = true;
+ // - all nodes must have a parent
+ // - non-doomed nodes must either:
+ // - be on the frontier or
+ // - have a non-doomed node closer to the frontier than themself
+ if (phase.isFrontier()) dead = false;
+ for(Result r : children)
+ if (state.doomed) { if (r.usedByAnyNode()) { dead = false; break; } }
+ else { if (r.usedByNonDoomedNode()) { dead = false; break; } }
+ dead |= results.size()==0;
+ if (!dead || destroyed) return;
+ destroyed = true;
+ while(children.size()>0)
+ for(Result r : children) {
+ children.remove(r);
+ r.destroy();
+ break;
+ }
+ while(results.size()>0)
+ for(Result r : results) {
+ results.remove(r);
+ r.removeChild(this);
+ break;
+ }
+ results = null;
+ children = null;