package modules.gradient;

import utils.*;
import simulator.*;
import java.util.*;

public class DistancePropagation implements PropagationTest {
  private final int limit;
  private final Object gid;
  public DistancePropagation(int l) {limit = l; gid=null;}
  public DistancePropagation(int l, Object gid) {limit = l; this.gid = gid; }

  public int getLimit() { return limit; }
  public boolean propagate(Gradient g, PortedProcessor pp) {
    if(gid==null) {
      return g.hopcount < limit;
    } else {
      ActiveGradient ag = (ActiveGradient)pp.getModule("ActiveGradient");
      Gradient g2 = ag.get(gid); 
      return (g2!=null && g2.hopcount < limit);
    }
  }
}
