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