Efficient algorithms for computing two nearest-neighbor problems on a rap