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


C++ Neighbors::reserve方法代码示例

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


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

示例1: find_neighbors_bruteforce_impl

Neighbors find_neighbors_bruteforce_impl(const RandomAccessIterator& begin, const RandomAccessIterator& end, 
                                         Callback callback, IndexType k)
{
	timed_context context("Distance sorting based neighbors search");
	typedef std::pair<RandomAccessIterator, ScalarType> DistanceRecord;
	typedef std::vector<DistanceRecord> Distances;

	Neighbors neighbors;
	neighbors.reserve(end-begin);
	for (RandomAccessIterator iter=begin; iter!=end; ++iter)
	{
		Distances distances;
		for (RandomAccessIterator around_iter=begin; around_iter!=end; ++around_iter)
			distances.push_back(std::make_pair(around_iter, callback.distance(iter,around_iter)));

		std::nth_element(distances.begin(),distances.begin()+k+1,distances.end(),
		                 distances_comparator<DistanceRecord>());

		LocalNeighbors local_neighbors;
		local_neighbors.reserve(k);
		for (typename Distances::const_iterator neighbors_iter=distances.begin(); 
				neighbors_iter!=distances.begin()+k+1; ++neighbors_iter)
		{
			if (neighbors_iter->first != iter) 
				local_neighbors.push_back(neighbors_iter->first - begin);
		}
		neighbors.push_back(local_neighbors);
	}
	return neighbors;
}
开发者ID:hushell,项目名称:shogun,代码行数:30,代码来源:neighbors.hpp

示例2: find_neighbors_vptree_impl

Neighbors find_neighbors_vptree_impl(const RandomAccessIterator& begin, const RandomAccessIterator& end, 
                                     Callback callback, IndexType k)
{
	timed_context context("VP-Tree based neighbors search");

	Neighbors neighbors;
	neighbors.reserve(end-begin);

	VantagePointTree<RandomAccessIterator,Callback> tree(begin,end,callback);

	for (RandomAccessIterator i=begin; i!=end; ++i)
	{
		LocalNeighbors local_neighbors = tree.search(i,k+1);
		std::remove(local_neighbors.begin(),local_neighbors.end(),i-begin);
		neighbors.push_back(local_neighbors);
	}

	return neighbors;
}
开发者ID:hushell,项目名称:shogun,代码行数:19,代码来源:neighbors.hpp


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