- public boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction) {
- return newNode(parent, pending, state, fromEmptyReduction, null); }
- public boolean newNode(Node parent, Forest pending, State state, boolean fromEmptyReduction, Reduction reduction) {
- int pos = parent==null?0:parent.phase()==null?0:parent.phase().pos;
- if (reduction!=null) {
- if (inhibited.contains(pos, reduction.position.owner())) return false;
- if (reduction.position.owner().needs != null) {
- for(Sequence s : reduction.position.owner().needs) {
- if (!performed.contains(pos, s)) {
- waiting.add(s, new Waiting(parent, pending, state, fromEmptyReduction, reduction));
- return false;
- }
- }
- }
- if ((reduction.position.owner().needed != null && reduction.position.owner().needed.size()>0) ||
- (reduction.position.owner().hated != null && reduction.position.owner().hated.size()>0) ||
- (reduction.position.owner().hates != null && reduction.position.owner().hates.size()>0))
- performed.add(pos, reduction.position.owner());
- }
- Node p = hash.get(code(state, parent==null?null:parent.phase()));
- boolean ret;
- if (reduction!=null) inhibit(reduction, parent==null?0:parent.phase().pos);
- if (p != null) ret = newNode2(p, parent, pending, state, fromEmptyReduction, reduction);
- else ret = newNode3(parent, pending, state, fromEmptyReduction, reduction);
- if (reduction != null) {
- boolean redo = true;
- while(redo) {
- redo = false;
- for(Waiting w : waiting.getAll(reduction.position.owner())) {
- if (w.parent==parent || (parent!=null&&w.parent!=null&&w.parent.phase()==parent.phase())) {
- waiting.remove(reduction.position.owner(), w);
- w.perform();
- redo = true;
- break;
- }
- }
- }
- }
- return ret;
- }
- private boolean newNode2(Node p, Node parent, Forest pending, State state, boolean fromEmptyReduction, Reduction reduction) {
- p.holder.merge(pending);
- if (p.parents().contains(parent)) return true;
- //if (p.fe && p.phase() != parent.phase()) throw new Error("yep yep");
- //if (!p.fe && p.phase() == parent.phase()) throw new Error("yep yep2");
- p.parents().add(parent, true);
- if (p!=parent && !fromEmptyReduction) p.queueReductions(parent);
- return true;
- }
- private boolean newNode3(Node parent, Forest pending, State state, boolean fromEmptyReduction, Reduction reduction) {