/* Computes d_{ID}(A+t,B) using one-dimensional range searching. Time complexity O(|M|\log m). */ static int processSparseFast(int m, int n, matchList *M) { keyTypeNode *match; int i,d; int *values=(int*)malloc(sizeof(int)*(m+2)); unsigned int leaves = 1<<(log_2(m)+1); treeNode *A = CreateCompleteBinaryTree(leaves); values[0] = 0; insertLeaf(A,leaves, 0); for (i=1;i<=m+1;i++) values[i]=INT_MAX; match = M->first->next; while (match != NULL) { i = predecessor(A,leaves,match->key.i); insertLeaf(A,leaves, match->key.i); if (values[i]-2<values[match->key.i]) { values[match->key.i] = values[i]-2; deleteGreaterSuccessors(A,leaves,match->key.i,values); } match = match->next; } d = values[m+1]+m+n+2; free(values); free(A); return d; }
/* Reports {j} such that d_{ID}(A + t, T_{j'...j}) <= k. Time complexity is O(|M|\log m). */ static void searchOccurrences(int m, int k, int t, matchList *M, occType* occ) { keyTypeNode *match; int i,d,value; int *values=(int*)malloc(sizeof(int)*(m+2)); unsigned int leaves = 1<<(log_2(m)+1); treeNode *A = CreateCompleteBinaryTree(leaves); values[0] = 0; insertLeaf(A,leaves, 0); for (i=1;i<=m+1;i++) values[i]=INT_MAX; match = M->first->next; /* discard the pair (m+1,n+1) since it is only used in the distance computation (hence using match->next != NULL) */ while (match->next != NULL) { i = predecessor(A,leaves,match->key.i); /* let's check if cheeper to start a new occurrence */ d = min2(values[i]-2,-match->key.j-1); insertLeaf(A,leaves, match->key.i); if (d<values[match->key.i]) { values[match->key.i] = d; deleteGreaterSuccessors(A,leaves,match->key.i,values); } /* We should report an interval [key.j,j] on the last row, where the current point induces occurrences d_{ID}(A+t,T_{j''...j'})<=k, where j' in [key.j,j]. However, since d_{ID}(A+t,T_{j''...key.j}) will be the best occurrence induced by the current point, let's just report it. */ value = d+match->key.j+m; if (value <= k && value < occ[match->key.j].value) { occ[match->key.j].value = value; occ[match->key.j].t = t; } match = match->next; } free(values); free(A); }
// A function to insert the element to the tree node insertion(node cur,int e) { node sib,temp,r; // If node is not full if(cur->num<4) { cur=insertLeaf(cur,e); return cur; } //If node is full then split else if(cur->num==4) { sib=makeNode(); sib=split(cur,sib); if(cur->leaf==1) { sib=insertLeaf(sib,e); // If node is root if(cur->r==1) { temp=makeNode(); cur->r=0; temp->r=1; cur->p=temp; sib->p=temp; temp->leaf=0; temp->ptr[0]=cur; temp->ptr[1]=sib; temp->d[0]=sib->d[0]; (temp->num)++; root=temp; return cur; } cur->p=insertParent(cur,sib->d[0],sib); return cur; } } }
//------------------------------------------------------- coBVHNode* coBVH::insert (const coAABB& _aabb, coUint32 _userData) { coBVHNode* leaf = allocateNode(); leaf->m_aabb = _aabb; //leaf->m_parent = nullptr; // insertLeaf will init leaf->m_children[1] = nullptr; leaf->m_userData = _userData; insertLeaf(m_root, *leaf); return leaf; }
void BPTree::insert(Value key,PtrType pointer) { PtrType nodePtr = findLeafNode(key); Node node(dbName,nodePtr,indexName,tableInstance,n); if (node.getCount() < (n - 1)) insertLeaf(node,key,pointer); else { //排序 vector<Value> keyList = node.getInfo();//只读键值对 if (isLess(key,keyList[0])) { keyList.insert(keyList.begin(),key); Value temp(_TYPE_INT,pointer); keyList.insert(keyList.begin(),temp); } else { for (int i = (keyList.size() - 1 - 1); i >= 0; i-=2) { if (isLessEqual(keyList.at(i),key)) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin() + i+1,tempPtr); keyList.insert(keyList.begin() + i+2,key); break; } } } //更新尾指针 Node newNode(dbName,indexName,tableInstance,n); PtrType newNodePtr = newNode.getNodePtr(); newNode.setLastPtr(node.getLastPtr()); node.setLastPtr(newNodePtr); //赋值元素到该到的地方 int breakPoint = 0; if (n % 2 == 0) breakPoint = (n /2)*2; else breakPoint = ((n / 2) + 1)*2; vector<Value> temp(keyList.begin(),keyList.begin() + breakPoint); node.set(temp);//只写键值对 vector<Value> temp2(keyList.begin() + breakPoint,keyList.end());//TODO:左闭右开? newNode.set(temp2); insertNonleaf(node,temp2[0],newNodePtr); } }
tuint SWDynamicTree2D::createProxy( const taabb2d& aabb, void* userData ) { tuint proxyID = allocNode(); tvec2 extension( SW_AddedExtension, SW_AddedExtension ); TreeNode& node = m_nodes[proxyID]; node.aabb = aabb; node.aabb.lower -= extension; node.aabb.upper += extension; node.userData = userData; insertLeaf( proxyID ); return proxyID; }
bool SWDynamicTree2D::updateProxy( tuint proxyID, const taabb2d& aabb ) { if ( proxyID >= m_nodes.size() ) return false; TreeNode& node = m_nodes[proxyID]; if ( node.aabb.contains( aabb ) ) return false; removeLeaf( proxyID ); tvec2 extention( SW_AddedExtension, SW_AddedExtension ); node.aabb = aabb; node.aabb.lower -= extention; node.aabb.upper += extention; insertLeaf( proxyID ); return true; }
// insert the specified key in the Btree // the tree needs to be opened first by the caller RC insertKey(BTreeHandle* tree, Value* key, RID rid) { Btree_stat *root = tree->mgmtData; Btree *node = root->mgmtData; int i; if (!root->num_nodes) { // tree is empty root->num_nodes++; // create a new nodes createNew(node, key, rid); // the toptal number of nodes change root->num_inserts = root->num_inserts + 1; // update the statistic info of the tree updateStat(tree, root); return RC_OK; } // find a place where the new node should go node = find_node_to_insert(root, key); // traverse till the end Btree* temp1 = Rootnode; while (temp1) { for (i = 0; i < temp1->num_keys; i++) { // check if theres a match if (temp1->keys[i] == key->v.intV) { // update the stat info updateStat(tree, root); return RC_OK; } } temp1 = temp1->next; } // check which side should we traverse if (node->num_keys < root->order) { // this is a leaf node insertLeaf(node, key, rid); root->num_inserts = root->num_inserts + 1; // update the stat info updateStat(tree, root); return RC_OK; } // check if we got aq match if (node->num_keys == root->order) { // split the current node and insert splitInsert(tree, root, node, key, rid); root->num_inserts = root->num_inserts + 1; // update the stat info updateStat(tree, root); return RC_OK; } // ok return RC_OK; }