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


C++ NodePtr::closest方法代码示例

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


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

示例1: insert

/* This appends `this` to the node `node` */
NodePtr insert(NodePtr thIs, NodePtr node)
{
	int la = thIs->level; // node to be inserted
	int lb = node->level; // node where insertation
	assert(la < lb); // node to be inserted must have lower level then parent
	//if (thIs->parent) assert(find_in_tree1(thIs) == true);
	NodePtr q = NULL;
	NodePtr chd = NULL;
	node->move(thIs);
	if (la == lb - 1)
	{
    node->child.push_back(thIs);
		thIs->parent = node;
		if (node->child.size() > MAX_NODE_SZ &&  node->tree->canSplit() ) // with us as additional child `node` is now too large :(
			return (node->reinserted || node->parent == NULL) ? split(node) : reinsert(node);
	}
	else // la < lb - 1
	{
		chd = thIs->closest(node->child);
		q = insert(thIs, chd);
	}
	if ((node->updateCount + 1) % UPDATE_EVERY == 0)
		node->update();
	else
	{
		if (q) node->remove(q);
		node->inflate(chd);
	}

  return q;
}
开发者ID:RemiLacroix-IDRIS,项目名称:XIOS,代码行数:32,代码来源:node.cpp

示例2: split

NodePtr split(NodePtr thIs)
{
	thIs->tree->increaseLevelSize(thIs->level);
	NodePtr p = new Node;
	NodePtr q = new Node;
	p->level = q->level = thIs->level;
	p->reinserted = q->reinserted = false;
	p->parent = q->parent = thIs->parent;
	p->tree = q->tree = thIs->tree;


	p->child.resize(MAX_NODE_SZ/2);
	q->child.resize(MAX_NODE_SZ/2 + 1);
	assert(thIs->child.size() == MAX_NODE_SZ+1);
	thIs->tree->ref = thIs->closest(thIs->child, FARTHEST); // farthest from centre
	std::sort(thIs->child.begin(), thIs->child.end(), compareDist);
	for (int i = 0; i < MAX_NODE_SZ+1; i++)
		assert(thIs->child[i]->parent == thIs);
	for (int i = 0; i < MAX_NODE_SZ/2 + 1; i++)
		q->child[i] = thIs->child[i];
	for (int i = MAX_NODE_SZ/2+1; i<MAX_NODE_SZ+1; i++)
		p->child[i-MAX_NODE_SZ/2-1] = thIs->child[i];
	for (int i = 0; i < MAX_NODE_SZ/2 + 1; i++)
		q->child[i]->parent = q;
	for (int i = MAX_NODE_SZ/2+1; i < MAX_NODE_SZ+1; i++)
		p->child[i-MAX_NODE_SZ/2-1]->parent = p;
	p->update();
	q->update();
   
	if (squaredist(thIs->centre, q->centre) < squaredist(thIs->centre, p->centre))
		swap(p, q);

	thIs->child = p->child; // now our children do not know we are their parents and believe p is their parent
	for (int i = 0; i < thIs->child.size(); i++)
		thIs->child[i]->parent = thIs;
	thIs->reinserted = p->reinserted;
	thIs->update();
	delete p;

	if (thIs == thIs->tree->root) // root split
	{
		// since we currently are root, make new root and make us and q its children
		thIs->tree->newRoot(thIs->level + 1);
		thIs->tree->root->child.push_back(thIs);  thIs->parent = thIs->tree->root;
		thIs->tree->root->child.push_back(q);     q->parent    = thIs->tree->root;
		thIs->tree->root->update();
	}
	else
	{
		thIs->tree->push_front(q);
	}  // push_front?

  	return q;
}
开发者ID:RemiLacroix-IDRIS,项目名称:XIOS,代码行数:54,代码来源:node.cpp

示例3: routeNode

// Each sample node has a rank randomly assigned to it, assign `node` from full tree
void Node::routeNode(NodePtr node, int level)
{
	NodePtr closest;

	double distMin2 = 0; // squared distance
	closest = NULL;
	if (tree->root == this)
		findClosest(level, node, distMin2, closest);

	if (closest != NULL && tree->root == this)
		/* When is this point reached?
		   if the preceeding findClosest was called and succesed to set closest
		   findClosest sets closest if we are `level` or src is in our circle (=> belongs to child of ours)
		   => reached if we are not `level` and node is not child of us
		*/
		node->route = closest->route;
	else  /* find closest was not successfull or we were not root */
	{
		if (this->level == level)
			node->route = this->route;
		else /* not yet right level => go down one more */
			node->closest(this->child)->routeNode(node, level);
	}
}
开发者ID:RemiLacroix-IDRIS,项目名称:XIOS,代码行数:25,代码来源:node.cpp


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