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


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

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


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

示例1:

//insert an new Entry, whose entity doesn't exist before 
bool 
VSTree::insertEntry(const SigEntry& _entry)
{

	//choose the best leaf node to insert the _entry 
    VNode* choosedNodePtr = this->chooseNode(this->getRoot(), _entry);

#ifdef DEBUG_VSTREE
		if (_entry.getEntityId() == 4000001)
		{
			stringstream _ss;
			if (choosedNodePtr)
			{
				_ss << "insert " << _entry.getEntityId()
					<< " into [" << choosedNodePtr->getFileLine() << "],\t";
				_ss << "whose childnum is " << choosedNodePtr->getChildNum() << endl;
			}
			else
			{
				_ss << "insert " << _entry.getEntityId() << " , can not choose a leaf node to insert entry. @VSTree::insert" << endl;
			}
			Util::logging(_ss.str());
		}
#endif

    if (choosedNodePtr == NULL)
    {
        cerr << "error, can not choose a leaf node to insert entry. @VSTree::insert" << endl;
        return false;
    }

    if (choosedNodePtr->isFull())
    {
		 //if the choosed leaf node to insert is full, the node should be split.
        this->split(choosedNodePtr, _entry, NULL);

        //debug
//        if (!choosedNodePtr->checkState())
//        {
//            stringstream _ss;
//            _ss << "node " << choosedNodePtr->getFileLine() << " childFileLine error. after split" << endl;
//            Util::logging(_ss.str());
//        }
    }
    else
    {
        choosedNodePtr->addChildEntry(_entry, false);
        choosedNodePtr->refreshAncestorSignature(*(this->node_buffer));

        //debug
//        if (!choosedNodePtr->checkState())
//        {
//            stringstream _ss;
//            _ss << "node " << choosedNodePtr->getFileLine() << " childFileLine error. after addChildEntry" << endl;
//            _ss <<"child num=" << choosedNodePtr->getChildNum() << endl;
//            _ss <<"node num=" << this->node_num << " entry num=" << this->entry_num << endl;
//            Util::logging(_ss.str());
//        }

        // update the entityID2FileLineMap.
        this->entityID2FileLineMap[_entry.getEntityId()] = choosedNodePtr->getFileLine();
    }
    this->entry_num ++;

    return true;
}
开发者ID:smilezcc,项目名称:gStore,代码行数:67,代码来源: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::addChildEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。