当前位置: 首页>>代码示例>>C++>>正文


C++ KDTree::Delete方法代码示例

本文整理汇总了C++中KDTree::Delete方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::Delete方法的具体用法?C++ KDTree::Delete怎么用?C++ KDTree::Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KDTree的用法示例。


在下文中一共展示了KDTree::Delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[])
{
	KDTree<Value, 2> kdtree = KDTree<Value, 2>::CreateKDTree(INSERT_NUM);

	std::vector<KDTree<Value, 2>::DataType> vData;
	for(uint32_t i=0; i<INSERT_NUM; ++i)
	{
		KDTree<Value, 2>::DataType item;
		item.Vector[0] = random() % 99;
		item.Vector[1] = random() % 99;
		item.Value.Uin = i;

		vData.push_back(item);
		//printf("new vector (%u, %u)\n", item.Vector[0], item.Vector[1]);
	}

	timeval t1, t2;
	gettimeofday(&t1, NULL);
	kdtree.Build(vData);
	gettimeofday(&t2, NULL);
	printf("const: %.03fs\n", TIME_COST(t1, t2));

	printf("Tree Dump:\n");
	kdtree.DumpTree();

	printf("\n");

	KDTree<Value, 2>::VectorType key;
	key[0] = (random() * time(NULL)) % 99;
	key[1] = (random() * time(NULL)) % 99;

	kdtree.Draw2DMap("map.jpg", key[0], key[1]);

#define SEARCH_COUNT	5

	uint32_t range = 0;

	KDTree<Value, 2>::DataType buffer[SEARCH_COUNT];
	int foundCount = kdtree.Nearest(key, buffer, SEARCH_COUNT);
	printf("nearest (%u, %u):\n", key[0], key[1]);
	for(int i=0; i<foundCount; ++i)
	{
		uint32_t distance = EuclideanDistance<uint32_t, KDVector<uint32_t, 2>, 2>::Distance(key, buffer[i].Vector);
		if(i == foundCount / 2)
			range = distance;
		printf("  %d:(%u, %u) distance:%u\n", i, buffer[i].Vector[0], buffer[i].Vector[1], distance);
	}

	printf("\n");

	foundCount = kdtree.Range(key, range, buffer, SEARCH_COUNT);
	printf("nearest (%u, %u) with range %u:\n", key[0], key[1], range);
	for(int i=0; i<foundCount; ++i)
	{
		uint32_t distance = EuclideanDistance<uint32_t, KDVector<uint32_t, 2>, 2>::Distance(key, buffer[i].Vector);
		printf("  %d:(%u, %u) distance:%u\n", i, buffer[i].Vector[0], buffer[i].Vector[1], distance);
	}

	printf("\n");

	kdtree.Delete();
	return 0;
}
开发者ID:seerhan,项目名称:libnindex,代码行数:63,代码来源:kdtree_main.cpp


注:本文中的KDTree::Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。