void InsertBTree(BTNode *&t, KeyType k, BTNode *q, int i) { /*在m阶t树t上结点*q的key[i]与key[i+1]之间插入关键字k。若引起 结点过大,则沿双亲链进行必要的结点分裂调整,使t仍是m阶t树。*/ BTNode *ap; int finished,needNewRoot,s; KeyType x; if (q==NULL) //t是空树(参数q初值为NULL) NewRoot(t,NULL,k,NULL); //生成仅含关键字k的根结点*t else { x=k;ap=NULL;finished=needNewRoot=0; while (needNewRoot==0 && finished==0) { Insert(q,i,x,ap); //将x和ap分别插入到q->key[i+1]和q->ptr[i+1] if (q->keynum<=Max) finished=1; //插入完成 else { //分裂结点*q,将q->key[s+1..m],q->ptr[s..m]和q->recptr[s+1..m]移入新结点*ap s=(m+1)/2; Split(q,ap); x=q->key[s]; if (q->parent) //在双亲结点*q中查找x的插入位置 { q=q->parent;i=Search(q, x); } else needNewRoot=1; } } if (needNewRoot==1) //根结点已分裂为结点*q和*ap NewRoot(t,q,x,ap); //生成新根结点*t,q和ap为子树指针 } }
/* 结点过大,则沿双亲链进行必要的结点分裂调整,使T仍是m阶B树。 */ void InsertBTree(BTree *T,int key,BTree q,int i) { BTree ap=NULL; Status finished=FALSE; int s; int rx; rx=key; while(q&&!finished) { Insert(&q,i,rx,ap); /* 将r->key、r和ap分别插入到q->key[i+1]、q->recptr[i+1]和q->ptr[i+1]中 */ if(q->keynum<m) finished=TRUE; /* 插入完成 */ else { /* 分裂结点*q */ s=(m+1)/2; rx=q->node[s].recptr; split(&q,&ap); /* 将q->key[s+1..m],q->ptr[s..m]和q->recptr[s+1..m]移入新结点*ap */ q=q->parent; if(q) i=Search(q,key); /* 在双亲结点*q中查找rx->key的插入位置 */ } } if(!finished) /* T是空树(参数q初值为NULL)或根结点已分裂为结点*q和*ap */ NewRoot(T,rx,ap); /* 生成含信息(T,rx,ap)的新的根结点*T,原T和ap为子树指针 */ }
InlineContext* InlineStrategy::GetRootContext() { if (m_RootContext == nullptr) { // Allocate on first demand. m_RootContext = NewRoot(); // Estimate how long the jit will take if there's no inlining // done to this method. m_InitialTimeEstimate = EstimateTime(m_RootContext); m_CurrentTimeEstimate = m_InitialTimeEstimate; // Set the initial budget for inlining. Note this is // deliberately set very high and is intended to catch // only pathological runaway inline cases. m_InitialTimeBudget = BUDGET * m_InitialTimeEstimate; m_CurrentTimeBudget = m_InitialTimeBudget; // Estimate the code size if there's no inlining m_InitialSizeEstimate = EstimateSize(m_RootContext); m_CurrentSizeEstimate = m_InitialSizeEstimate; // Sanity check assert(m_CurrentTimeEstimate > 0); assert(m_CurrentSizeEstimate > 0); } return m_RootContext; }
int InsertBTree(NodeType **t, ElemType *xelm) { int s, finished = false; NodeType *stptr; KeyType kx = xelem->key; ElemType *elemptr = xelm; Result rs; rs = SearchBTree(*t, kx); if (!rs.tag) { stptr = NULL; while (rs.pt && !finished) { Insert(rs.pt, rs.i, kx, elemptr, stptr); if (rs.pt->keynum < m) finished = true; else { s = (m + 1) / 2; kx = rs.pt->key[s]; elemptr = rs.pt->eptr[s]; stptr = split(rs.pt, s); rs.pt = rs.pt->parent; if (rs.pt) rs.i = Search(rs.pt, kx); } } if (!finished) { *t = NewRoot(*t, stptr, kx, elemptr); finished = true; } } }
void JTree::SetRoot ( JTreeNode* root ) { assert( root != NULL ); itsRoot = root; itsRoot->ShouldBeOpenable(kJTrue); itsRoot->SetTree(this); Broadcast(NewRoot()); }
Boolean Two3<KeyType>::Insert(const Element<KeyType>& y) { Two3Node<KeyType> *p; Element<KeyType> x = y; if (x.key == MAXKEY) return FALSE; if (!root) { NewRoot(x, 0); return TRUE;} if (!(p = FindNode(x))) {/*InsertionError(); */ return FALSE;} for (Two3Node<KeyType> *a = 0;;) if (p->dataR.key == MAXKEY) { p->PutIn(x,a); return TRUE; } else { Two3Node<KeyType> *olda = a; a = new(Two3Node<KeyType>); x = Split(p, x, olda, a); if (root == p) { NewRoot(x, a); return TRUE; } else p = p->parent; } }
CL_DiskBTreeNodeSpace::CL_DiskBTreeNodeSpace (short order, CL_ByteStringStore& store, const CL_DiskBTree& tree, CL_AbstractComparator& cmp, CL_ObjectBuilder* f, bool create) :CL_BTreeNodeSpace (order, tree._tree, cmp), _store (store) { if (!f) CL_Error::Warning ("DiskBTree constructor: null builder function"); _builder = f; if (create) { CL_BTreeNodeHandle h = CreateNode (); NewRoot (h); } _tmp = NULL; }
//B-树的插入算法 Status InsertBTree(BTree &T,KeyType K,BTree q,int i) { //在m阶B-树T上结点*q的key[i]与key[i+1]之间插入关键字K //若引入结点过大,则沿双亲链进行必要的节点分裂调整,使T仍是m阶B-树 x=K; ap=NULL; finished=FALSE; while(q&&!finished) { Insert(q,i,x,ap); //将x和ap分别插入到q->key[i+1]和q->ptr[i+1] if(q->keynum<m)finished=TRUE; else{ s=m/2; split(q,s,ap); //分裂*q,将q->key[s+1..m],q->ptr[s..m]和q->recptr[s+1..m]移入新结点*ap中 x=q->key[s]; q=q->parent; if(q)i=Search(q,x); //在双亲结点*q中寻找x的插入位置 } } if(!finished) //T是空树或根结点已分裂为结点*q和*ap NewRoot(T,q,x,ap); //生成含信息(T,x,ap)的新的根结点*T,原T和ap为子树指针 return TRUE; }