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


C++ VNode::getChild方法代码示例

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


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

示例1: if

//the _entry_index in _child is to be removed.
//node can only be deleted in this function.
void 
VSTree::coalesce(VNode* _child, int _entry_index)
{
#ifdef DEBUG
	cout << "coalesce happen" <<endl;
#endif

	//found the father and index
	VNode* _father = _child->getFather(*(this->node_buffer));
	int cn = _child->getChildNum();
	
	if(_father == NULL) //this is already root
	{
		//NOTICE:when root is leaf, at least one key, otherwise the tree is empty
		//But when root is internal, at least two key, if one key then shrink
		//(1-key internal root is not permitted)
		//
		//Notice that leaf-root case has been discussed in upper function removeEntry()
		//so here the root must be internal node
		_child->removeChild(_entry_index);
		if(cn == 2)
		{
			//only one key after remove, shrink root
			VNode* newRoot = _child->getChild(0, *(this->node_buffer));
			newRoot->setAsRoot(true);
			cout<<"shrink root in coalesce() -- to swap node file"<<endl;
			this->swapNodeFileLine(newRoot, _child);
			this->root_file_line = newRoot->getFileLine();
			this->height--;
			this->removeNode(_child);
		}
		return;
	}

	if(cn > VNode::MIN_CHILD_NUM)
	{
		cout<<"no need to move or union in coalesce()"<<endl;
		_child->removeChild(_entry_index);
		_child->refreshAncestorSignature(*(this->node_buffer));
		return;
	}

    int fn = _father->getChildNum();
	int i, _child_index = -1;

	for (i = 0; i < fn; ++i)
	{
		if (_father->getChildFileLine(i) == _child->getFileLine())
		{
			break;
		}
	}
	if(i == fn)
	{
		cerr << "not found the leaf node in VSTree::coalesce()" << endl;
		return;
	}
	else
	{
		_child_index = i;
	}

	//_child->removeChild(_entry_index);
	//_child->setChildNum(cn);

	//NOTICE:we do not consider the efficiency here, so just ensure the operation is right
	//BETTER:find good way to ensure signatures are separated(maybe similar ones together)
	int ccase = 0;
	VNode* p = NULL;
	int n = 0;

	if(_child_index < fn - 1)
	{
		p = _father->getChild(_child_index+1, *(this->node_buffer));
		n = p->getChildNum();
		if(n > VNode::MIN_CHILD_NUM)
		{
			ccase = 2;
		}
		else
		{
			ccase = 1;
		}
	}

	if(_child_index > 0)
	{
		VNode* tp = _father->getChild(_child_index-1, *(this->node_buffer));
		int tn = tp->getChildNum();
		if(ccase < 2)
		{
			if(ccase == 0)
				ccase = 3;
			if(tn > VNode::MIN_CHILD_NUM)
				ccase = 4;
		}
		if(ccase > 2)
		{
//.........这里部分代码省略.........
开发者ID:bnu05pp,项目名称:gStoreD,代码行数:101,代码来源:VSTree.cpp

示例2: sort

void 
VSTree::split(VNode* _p_node_being_split, const SigEntry& _insert_entry, VNode* _p_insert_node)
{
#ifdef DEBUG_VSTREE
		stringstream _ss;
		_ss << "**********************split happen at "
			<< _p_node_being_split->getFileLine() << endl;
		_ss << _p_node_being_split->to_str() << endl;
		Util::logging(_ss.str());
#endif
    // first, add the new child node(if not leaf) or child entry(if leaf) to the full node.
	bool just_insert_entry = (_p_insert_node == NULL);
    if(just_insert_entry)
    {
        _p_node_being_split->addChildEntry(_insert_entry, true);
    }
    else
    {
        _p_node_being_split->addChildNode(_p_insert_node, true);
    }

    SigEntry entryA, entryB;

	//BETTER: use hanming, xor result or the vector included angle to guess the distince.
	//And then also use the farest two as seeds.
	//
     //two seeds to generate two new nodes.
	 //seedA kernel: the SigEntry with the minimal count of signature.
	 //seedB kernel: the SigEntry with the maximal count of signature.
     

    int maxCount = 0; // record the minimal signature count.
    int entryA_index = 0; // record the seedA kernel index.
    for(int i = 0; i < VNode::MAX_CHILD_NUM; i++)
    {
        int currentCount = (int) _p_node_being_split->getChildEntry(i).getSigCount();
        if(maxCount < currentCount)
        {
            maxCount = currentCount;
            entryA_index = i;
        }
    }
    entryA = _p_node_being_split->getChildEntry(entryA_index);

	maxCount = 0;
    int entryB_index = 0; // record the seedB kernel index.
    for(int i = 0; i < VNode::MAX_CHILD_NUM; i++)
    {
		//NOTICE:I think xOR should be used here to choose the farest two
		int currentCount = entryA.xOR(_p_node_being_split->getChildEntry(i));
		//int currentCount = entryA.xEpsilen(_p_node_being_split->getChildEntry(i));
        if(i != entryA_index && maxCount <= currentCount)
        {
            maxCount = currentCount;
            entryB_index = i;
        }
    }
    entryB = _p_node_being_split->getChildEntry(entryB_index);

    // AEntryIndex: the entry index near seedA.
    // BEntryIndex: the entry index near seedB.
    std::vector<int> entryIndex_nearA, entryIndex_nearB;
    entryIndex_nearA.clear();
    entryIndex_nearB.clear();
    entryIndex_nearA.push_back(entryA_index);
    entryIndex_nearB.push_back(entryB_index);

    int nearA_max_size, nearB_max_size;
    bool nearA_tooSmall, nearB_tooSmall;

    for(int i = 0; i < VNode::MAX_CHILD_NUM; i++)
    {
        if(i == entryA_index || i == entryB_index) continue;

		//should guarantee that each new node has at least MIN_CHILD_NUM children. 
        nearA_max_size = VNode::MAX_CHILD_NUM - entryIndex_nearB.size();
        nearA_tooSmall = (nearA_max_size <= VNode::MIN_CHILD_NUM);

        if(nearA_tooSmall)
        {
            for(; i < VNode::MAX_CHILD_NUM; i++)
            {
                if (i == entryA_index || i == entryB_index) continue;
                entryIndex_nearA.push_back(i);
            }
            break;
        }

        nearB_max_size = VNode::MAX_CHILD_NUM - entryIndex_nearA.size();
        nearB_tooSmall = (nearB_max_size <= VNode::MIN_CHILD_NUM);
        if(nearB_tooSmall)
        {
            for(; i < VNode::MAX_CHILD_NUM; i++)
            {
                if(i == entryA_index || i == entryB_index) continue;
                entryIndex_nearB.push_back(i);
            }
            break;
        }

//.........这里部分代码省略.........
开发者ID:smilezcc,项目名称:gStore,代码行数:101,代码来源:VSTree.cpp

示例3: split

void VSTree::split(VNode* _p_node_being_split, const SigEntry& _insert_entry, VNode* _p_insert_node)
{
    //debug
//	{
//		stringstream _ss;
//		_ss << "**********************split happen at "
//			<< _p_node_being_split->getFileLine() << endl;
//		_ss << _p_node_being_split->to_str() << endl;
//		Util::logging(_ss.str());
//	}
    // first, add the new child node(if not leaf) or child entry(if leaf) to the full node.
	bool just_insert_entry = (_p_insert_node == NULL);
    if (just_insert_entry)
    {
        _p_node_being_split->addChildEntry(_insert_entry, true);
    }
    else
    {
        _p_node_being_split->addChildNode(_p_insert_node, true);
    }

    SigEntry entryA, entryB;
    /* two seeds to generate two new nodes.
     * seedA kernel: the SigEntry with the minimal count of signature.
     * seedB kernel: the SigEntry with the second minimal count of signature.
     * */

    int minCount = 0; // record the minimal signature count.
    int entryA_index = 0; // record the seedA kernel index.
    for (int i=0;i<VNode::MAX_CHILD_NUM;i++)
    {
        int currentCount = (int) _p_node_being_split->getChildEntry(i).getSigCount();
        if (minCount < currentCount)
        {
            minCount = currentCount;
            entryA_index = i;
        }
    }
    entryA = _p_node_being_split->getChildEntry(entryA_index);

    minCount = 0;
    int entryB_index = 0; // record the seedB kernel index.
    for (int i=0;i<VNode::MAX_CHILD_NUM;i++)
    {
        int currentCount = entryA.xEpsilen(_p_node_being_split->getChildEntry(i));
        if (i != entryA_index && minCount <= currentCount)
        {
            minCount = currentCount;
            entryB_index = i;
        }
    }
    entryB = _p_node_being_split->getChildEntry(entryB_index);

    // AEntryIndex: the entry index near seedA.
    // BEntryIndex: the entry index near seedB.
    std::vector<int> entryIndex_nearA, entryIndex_nearB;
    entryIndex_nearA.clear();
    entryIndex_nearB.clear();
    entryIndex_nearA.push_back(entryA_index);
    entryIndex_nearB.push_back(entryB_index);

    /* just tmp variables, for more readibility */
    int nearA_max_size, nearB_max_size;
    bool nearA_tooSmall, nearB_tooSmall;

    for (int i=0;i<VNode::MAX_CHILD_NUM;i++)
    {
        if (i == entryA_index || i == entryB_index) continue;

        /* should guarantee that each new node has at least MIN_CHILD_NUM children. */
        nearA_max_size = VNode::MAX_CHILD_NUM - entryIndex_nearB.size();
        nearA_tooSmall = (nearA_max_size <= VNode::MIN_CHILD_NUM);

        if (nearA_tooSmall)
        {
            for (;i<VNode::MAX_CHILD_NUM;i++)
            {
                if (i == entryA_index || i == entryB_index) continue;
                entryIndex_nearA.push_back(i);
            }
            break;
        }

        nearB_max_size = VNode::MAX_CHILD_NUM - entryIndex_nearA.size();
        nearB_tooSmall = (nearB_max_size <= VNode::MIN_CHILD_NUM);
        if (nearB_tooSmall)
        {
            for (;i<VNode::MAX_CHILD_NUM;i++)
            {
                if (i == entryA_index || i == entryB_index) continue;
                entryIndex_nearB.push_back(i);
            }
            break;
        }

        /* calculate the distance from
         * the i-th child entry signature to seedA(or seedB).*/

        /*debug target 1*/
        int disToSeedA = entryA.xEpsilen(_p_node_being_split->getChildEntry(i));
//.........这里部分代码省略.........
开发者ID:zhangxiaoyang,项目名称:gStore,代码行数:101,代码来源:VSTree.cpp


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