Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用KDTree对任意维度进行top-k查询和范围查询_C++_Performance_Data Structures_Kdtree - Fatal编程技术网

C++ 如何使用KDTree对任意维度进行top-k查询和范围查询

C++ 如何使用KDTree对任意维度进行top-k查询和范围查询,c++,performance,data-structures,kdtree,C++,Performance,Data Structures,Kdtree,我使用KD-tree(libkdtree++)来存储多维数据集,这里的要求是该数据集可以支持不同维度上的top-k/range查询。例如,KDTree树:查找具有最高点[1](y轴)值的前100个点 从libkdtree++的实现来看,类似的是“find_within_range”函数,但是它是基于“Manhattan distance”计算的,这里的“Manhattan distance”等于max(x_dist,max(y_dist,z_dist))。我怎么能在一维上使用范围查询呢?看看代码

我使用KD-tree(libkdtree++)来存储多维数据集,这里的要求是该数据集可以支持不同维度上的top-k/range查询。例如,KDTree树:查找具有最高点[1](y轴)值的前100个点


从libkdtree++的实现来看,类似的是“find_within_range”函数,但是它是基于“Manhattan distance”计算的,这里的“Manhattan distance”等于max(x_dist,max(y_dist,z_dist))。我怎么能在一维上使用范围查询呢?

看看代码,看起来你不能用一种简单的方式来实现,这太可笑了。如果我是你,我会被诱惑去破解图书馆或者写我自己的kd树。我想在他们的邮件列表上确认一下,但看起来你可能不得不这样做:

kdtreetype::_Region_ r(point_with_min_y);
r.set_low_bound(min_x, 0);
r.set_high_bound(max_x, 0);
r.set_low_bound(min_z, 2);
r.set_high_bound(max_z, 2);
r.set_high_bound((min_y + max_y) / 2, 1);

double search_min = min_y, search_max = max_y;

// binary search to get 100 points
int c;
while (c = tree.count_within_range(r) != 100) {
    if (c > 100) search_max = (search_min + search_max) / 2;
    else         search_min = (search_min + search_max) / 2;
    r.set_high_bound((search_min + search_max) / 2);
}

tree.visit_within_range(r, process_min_y_point);
这是一个非常低效的二进制搜索,搜索Y的count(用Y表示感谢。Region类可以解决我的问题!top-k查询不必那么精确,这意味着当tree.count\u在\u范围(r)内时