srecord noeq ProbabilisticDistanceBasedLookup( IProbabilisticScheduler scheduler, NavigableMap map, IVF1 action, double key) { swappable double distanceToProbability(double distance) { ret genericDistanceToProbability(distance); } run { Double closest = closestDoubleKey(map, key); if (closest == null) ret; double p = distanceToProbability(abs(closest-key)); scheduler.at(p, () -> action.get(closest)); scheduler.at(p, () -> walkLeft(closest)); scheduler.at(p, () -> walkRight(closest)); } void walkLeft(double x) { Double y = map.lowerKey(key); if (y == null) ret; double p = distanceToProbability(abs(y-key)); scheduler.at(p, () -> action.get(y)); scheduler.at(p, () -> walkLeft(y)); } void walkRight(double x) { Double y = map.higherKey(key); if (y == null) ret; double p = distanceToProbability(abs(y-key)); scheduler.at(p, () -> action.get(y)); scheduler.at(p, () -> walkRight(y)); } }