How to find the item with the closest distance in a huge list of items while still having Hash functionality?

Viewed 74

I have a long list of Vertices and their id's. I want to give their id's to a method and get the Vertices in a fast way because there are a lot of them, linear search takes too long.

I am doing this with HashSet<long id, Vertex v> for now, I also want to find the closest vertex to the coordinates I give to the method like find [X.XXXX, Y.YYYY] by comparing Vertex.getCoordinates() I want to do this in an efficient manner, which structure should I choose to use? Also calculate distance method requires sqrt(), I can use sqrDist() but still I want to improve.

I am planning to have a sorted list-like structure in parallel(at this point I choose time over space) and do a binarySearch() then return the closest one like that, is this a valid solution? How can I make Java use binarySearch() without implementing it on my own?

0 Answers
Related