Java find k closest points to a given 2D point, quickly
问题 I function that takes a set of points, checks their distance against a given point and returns an ordered set with the closest points first. In case 2 points have the same distance from the given point, both will be kept, no problem. I use that function to pick the k closest points to any user-given point with 2D coordinates. It's just a matter of picking the first k points from the ordered set. Right now it's something like this, and I guess the distance calculation is called again and again