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


C++ BTreeNode类代码示例

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


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

示例1: BTreeNode

void BTree::insert(int k)
{

    if (root == NULL)
    {

        root = new BTreeNode(t, true);
        root->keys[0] = k;
        root->n = 1;
    }
    else
    {

        if (root->n == 2*t-1)
        {

            BTreeNode *s = new BTreeNode(t, false);
            s->C[0] = root;
            s->splitChild(0, root);
            int i = 0;
            if (s->keys[0] < k)
                i++;
            s->C[i]->insertNonFull(k);
            root = s;
        }
        else
            root->insertNonFull(k);
    }
}
开发者ID:bismoy2013,项目名称:Two-Roads-Algorithmic-Challenge,代码行数:29,代码来源:bokmarket.cpp

示例2: BTreeNode

void BTree::addToNode(BTreeNode *node, BTreeElement *child) {
	if (!node->addChild(child->getMinId(), child)) {
		//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Node is full");
		BTreeNode *newNode = new BTreeNode(this, nodeCapacity);
		int oldMinId = node->getMinId();
		node->split(newNode);

		BTreeNode *addTo;
		if (node->getMinId() == -1 || child->getMinId() > node->getMinId())
			addTo = node;
		else
			addTo = newNode;

		if (!addTo->addChild(child->getMinId(), child)) {
		//	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Node add FAILED!");
			return;
		}

		if (node->getParent() == NULL) {
		//	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "This node's parent is null");
			BTreeNode *parent = new BTreeNode(this, nodeCapacity);
			parent->addChild(node->getMinId(), node);
			root = parent;
		}
		addToNode(node->getParent(), newNode);
	}
	//__android_log_print(ANDROID_LOG_INFO, "Jello",  "Added new node to parent");
}
开发者ID:tomahawkpl,项目名称:Jello,代码行数:28,代码来源:BTree.cpp

示例3: TEST

TEST(BTreeNodeTest, test) {
  BTreeNodeBuilder<ValueT> builder;
  builder.set_is_leaf(false);

  const char *key = "key";
  ValueT expected = 3;
  builder.addEntry(key, expected);

  stringstream ss;
  builder.save(ss);

  BTreeNode<ValueT> node;
  node.load(ss);

  ValueT value;
  node.find(key, value);
  EXPECT_EQ(expected, value);

  key = "test";
  expected = 0;
  node.find(key, value);
  EXPECT_EQ(expected, value);

  key = "kay";
  expected = 3;
  node.lowerBound(key, value);
  EXPECT_EQ(expected, value);
}
开发者ID:simpzan,项目名称:Trie,代码行数:28,代码来源:BTreeNodeTest.cpp

示例4: BTreeBase

QString Expression::processConstant( const QString & expr, bool * isConstant )
{
	bool temp;
	if (!isConstant)
		isConstant = &temp;
	
	QString code;
	
	// Make a tree to put the expression in.
	BTreeBase *tree = new BTreeBase();
	BTreeNode *root = new BTreeNode();

	// parse the expression into the tree
	buildTree(expr,tree,root,0);
	// compile the tree into assembly code
	tree->setRoot(root);
	tree->pruneTree(tree->root());
	//code = traverseTree(tree->root());
	// Look to see if it is a number
	if( root->type() == number )
	{
		code = root->value();
		*isConstant = true;
	}
	else
	{
		code = "";
		*isConstant = false;
	}
	
	// Note deleting the tree deletes all nodes, so the root
	// doesn't need deleting separately.
	delete tree;
	return code;
}
开发者ID:ktechlab,项目名称:ktechlab,代码行数:35,代码来源:expression.cpp

示例5: remove

BTreeNode* InternalNode::remove(int value) {  
	BTreeNode *leaf = NULL;

  for(int i = 0; i < count; i++) {
  	
  	if(i == 0 && value <= keys[i]) leaf = children[0];
  	if(i == count - 1 && value >= keys[i]) leaf = children[i];
  	if(value >= keys[i] && value < keys[i+1]) leaf = children[i];

		if(leaf != NULL) {
			leaf = leaf->remove(value);
				//keys[i]	= children[i]->getMinimum();

			for(int i = 0; i < count; i++) {
				if(children[i]->getCount() == 0) {
					
					for(; i < count - 1; i++) {
						children[i] = children[i + 1];
						keys[i] = keys[i + 1];
					}

					--count;
					break;
				}
			}
		}

	}

	this->tryBorrowing(); 
	this->prune();

	if(parent == NULL && this->count == 1) return this->children[0] ;
	else return this;
} // InternalNode::remove(int value)
开发者ID:zj9205,项目名称:ECS60,代码行数:35,代码来源:InternalNode.cpp

示例6: GetLeafNode

void BPlusTree::Insert(int key , int value)
{
	BTreeNode * node = GetLeafNode(key);
	if(node == NULL)
	{
		root = new BTreeNode();
		root->setLeaf(true);
		root->InsertIntoLeafNode(key ,value);
		return;

	}

	if(node->searchLeaf(key))
	{
		return;
	}
	if(node->isFull())
	{
		split(node ,key ,value);
	}
	else
	{
		node->InsertIntoLeafNode(key,value);
	}

}
开发者ID:PrakharJain,项目名称:MyPrograms,代码行数:26,代码来源:BTree.cpp

示例7: InternalNode

InternalNode* InternalNode::split(int value){
  InternalNode* newNode = new InternalNode(internalSize, leafSize, parent, this, NULL);
  sort();
  BTreeNode* oldRightNode = getRightSibling();
  
  if(oldRightNode){
    oldRightNode->setLeftSibling(newNode);
    newNode->setRightSibling(oldRightNode);
    newNode->setLeftSibling(this);
  }
  
  //cout << keys[0] << " " << keys[1] << " " << keys[2] << endl;
  //cout << children[0]->getMinimum() << " " << children[1]->getMinimum() << endl;

  for(int i = ((internalSize+1) / 2); i < internalSize; i++){
    //cout << "Internal: Inserting " << keys[i] << " into new Node" << endl;
    newNode->insert(keys[i]);
  }

  count = count - newNode->getCount();
  
  if(keys[0] > value){
    newNode->insert(keys[0]);
    keys[0] = value;
  }

  else{
    newNode->insert(value);
  }
  
  setRightSibling(newNode);
  
  return newNode;
}
开发者ID:michaelromero,项目名称:Algorithms_DataStructures_CPP,代码行数:34,代码来源:InternalNode.cpp

示例8: Delete_Tree

void Delete_Tree(BTreeNode *&tree)
{
	BTreeNode *NodeToDelete = tree;

	BTreeNode *TempNode;

	if (tree->Right == NULL)
		tree = tree->Left;
	else if (tree->Left == NULL)
		tree = tree->Right;
	else
	{
		TempNode = tree->Right;
		
		while (TempNode->Left != NULL)
			TempNode = TempNode->Left;

		TempNode->Left = tree->Left;

		tree = tree->Right;
	}
	Employee[NodeToDelete->Hash_Key()].free_flag = true;
		
	delete NodeToDelete;


}
开发者ID:NovaEric,项目名称:ENova_Cplusplus,代码行数:27,代码来源:Hash7.cpp

示例9: bzero

// The main function that inserts a new key in this B-Tree
void BTree::insert(int k)
{
	char varnam[64];

	// If tree is empty
	if (root == NULL)
	{
		bzero(varnam, 64);
		sprintf(varnam,"%d",count);
		strcat(varnam,"node");
		varnam[64]=0;
		// Allocate memory for root
		root =(BTreeNode *)nvalloc_(sizeof(BTreeNode), varnam, 0);
		//root = (BTreeNode *)nvalloc_(sizeof(BTreeNode));
		root->Initialize(root, t, true, count);	
		//root = new BTreeNode(t, true);
		root->keys[0] = k; // Insert key
		root->n = 1; // Update number of keys in root
	}
	else // If tree is not empty
	{
		// If root is full, then tree grows in height
		if (root->n == 2*t-1)
		{
			bzero(varnam, 64);
			sprintf(varnam,"%d",count);
			strcat(varnam,"node");
			varnam[64]=0;

			// Allocate memory for root
			BTreeNode *s =(BTreeNode *)nvalloc_(sizeof(BTreeNode), varnam, 0);
			s->Initialize(s, t, false, count);	
			// Allocate memory for new root
			//BTreeNode *s = new BTreeNode(t, false);
			BEGIN_OBJTRANS((void *)s,0);

			// Make old root as child of new root
			s->C[0] = root;

			// Split the old root and move 1 key to the new root
			s->splitChild(0, root);

			// New root has two children now. Decide which of the
			// two children is going to have new key
			int i = 0;
			if (s->keys[0] < k)
				i++;
			s->C[i]->insertNonFull(k);

			nvcommitobj((void *)s,0);

			// Change root
			root = s;
		}
		else // If root is not full, call insertNonFull for root
			root->insertNonFull(k);
	}
	count++;
}
开发者ID:harveson,项目名称:nvmalloc,代码行数:60,代码来源:btree_new_wrd_trans.c

示例10: findNode

void BTree::remove(string name) {
  //DELETE AT LEAF
  BTreeNode* leaf = findNode(root, name);
  if(leaf->find(name,EXACT)==NOTFOUND){
    cout << "TARGET NOT FOUND" << endl;
    return;
  }
  cout << "Found TARGET. Now deleting it. "<< endl;
  leaf=leaf->remove(name);
  cout << "DELETE SUCESSFULLY. Now ADJUSTING ROOT" <<endl;
  AdjustingRoot(leaf); 
}
开发者ID:confidential96,项目名称:CS130A-Final-Project,代码行数:12,代码来源:BTree.cpp

示例11: queue

void BTree::print()
{
  BTreeNode *BTreeNodePtr;
  Queue<BTreeNode*> queue(1000);

  queue.enqueue(root);
  while(!queue.isEmpty())
  {
    BTreeNodePtr = queue.dequeue();
    BTreeNodePtr->print(queue);
  } // while
} // BTree::print()
开发者ID:zj9205,项目名称:ECS60,代码行数:12,代码来源:BTree.cpp

示例12: remove

void BTree::remove(int value)
{  
  BTreeNode *ptr = root-> remove(value);
  if(ptr==root)
  {
    InternalNode *IPtr = static_cast < InternalNode * > (ptr);
    ptr = IPtr->firstChild();
    ptr->setParent(NULL);
    root = ptr;
  } 

// To be written by students
} // BTree::remove()
开发者ID:yrsun,项目名称:CollegeHWs,代码行数:13,代码来源:BTree.cpp

示例13: insert

void BTree::insert(const int value)
{
	BTreeNode* newReturn = root->insert(value);
	if(newReturn != NULL )
	{
		BTreeNode *oldRoot = root;
		InternalNode *newRoot= new InternalNode(internalSize, leafSize, NULL, NULL, NULL);
		newRoot->insert(oldRoot,newReturn);//set new parent's property
		oldRoot->setParent(newRoot);//set child point to parent
		newReturn->setParent(newRoot);
		root = newRoot;
	}
	// students must write this
} // BTree::insert()
开发者ID:hjchai,项目名称:ECS60,代码行数:14,代码来源:BTree.cpp

示例14: insert

void BTree::insert(const int value)
{
  BTreeNode *split = root->insert(value);

  if (split)	// LeafNode needs split
  {
    InternalNode *parent = new InternalNode(internalSize, leafSize, NULL,
                                              NULL, NULL);
    root->setParent(parent);	// set parents to root
    split->setParent(parent);
    parent->insert(root);	// should be on the left
    parent->insert(split);	// should be on the right
    root = parent;
  }  // if split needed
} // BTree::insert()
开发者ID:andytheyang,项目名称:ECS-60-p2,代码行数:15,代码来源:BTree.cpp

示例15: remove

void BTree::remove(int k)
{
	if (!root)
	{
		cout << "The tree is empty\n";
		return;
	}

	// Call the remove function for root
	root->remove(k);

	// If the root node has 0 keys, make its first child as the new root
	// if it has a child, otherwise set root as NULL
	if (root->n==0)
	{
		BTreeNode *tmp = root;
		if (root->leaf)
			root = NULL;
		else
			root = root->C[0];

		// Free the old root
		delete tmp;
	}
	return;
}
开发者ID:harveson,项目名称:nvmalloc,代码行数:26,代码来源:btree_new_wrd_trans.c


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