1 // Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.Sequence.Position;
5 import edu.berkeley.sbp.Sequence.Pos;
7 final class Reduction implements Comparable<Reduction> {
10 private GSS.Phase phase;
11 private Forest forest;
14 public Reduction(Node parent, Pos reduction, Forest forest, GSS.Phase target) {
15 this.reduction = reduction;
19 target.addReduction(this);
22 public int compareTo(Reduction r) {
23 if (parent.phase()!=null || r.parent.phase()!=null) {
24 if (parent.phase()==null) return 1;
25 if (r.parent.phase()==null) return -1;
26 if (parent.phase().pos < r.parent.phase().pos) return 1;
27 if (parent.phase().pos > r.parent.phase().pos) return -1;
30 int master = Parser.mastercache.comparePositions(reduction(), r.reduction());
31 if (master != 0 && master != signum(reduction.ord() - r.reduction.ord()))
32 throw new Error("master="+master+" and a="+reduction.ord()+" and b="+r.reduction.ord()+"\n"+reduction+"\n"+r.reduction);
34 return reduction.compareTo(r.reduction);
37 private int signum(int x) {
43 public void perform() { new Result(forest, parent, reduction, phase); }
44 public GSS.Phase parentPhase() { return parent.phase(); }
45 public Pos reduction() { return reduction; }
46 public GSS.Phase targetPhase() { return phase; }
47 public String toString() { return (parent.phase()==null ? 0 : parent.phase().pos) + ":"+reduction; }