I have used KD-tree(libkdtree++) to store a multi-dimensional data set, and the requirements here is this data set can support top-k/range queries on different dimensions. For example, a KDTree<3, Point> tree: to find the top 100 points whose have highest Point[1](y axis) values.
From the implementation of libkdtree++, what’s similar is the “find_within_range” functions, however it is counted based on “Manhattan distance”, which equals max(x_dist, max(y_dist, z_dist)) here. How can I just use range query on one dimension?
Looking at the code, it looks like you can’t do that in a straightforward way, ridiculously enough. If I were you I’d be tempted to either hack the library or write my own kd-tree. I’d ask on their mailing list to be sure, but it looks like you might have to do something like this:
This is a horribly inefficient binary search for the Y at which count(points with y <= Y) == 100. I’m not familiar with the library, but that’s the best I’ve got on a cursory inspection.