public Pc toNearPc(int line) {
        int n = tableLength();
        int nearPc = 0;
        int distance = 0;
        if (n > 0) {
            distance = lineNumber(0) - line;
            nearPc = startPc(0);
        }

        for (int i = 1; i < n; ++i) {
            int d = lineNumber(i) - line;
            if ((d < 0 && d > distance)
                || (d >= 0 && (d < distance || distance < 0))) { 
                    distance = d;
                    nearPc = startPc(i);
            }
        }

        Pc res = new Pc();
        res.index = nearPc;
        res.line = line + distance;
        return res;
    }