void MonocularManhattanBnb::TransferBuilding(const SE3<>& new_pose, double floor_z, MatI& orients) { // Compute scaling (TODO: actually use this) DiagonalMatrix<3> Mscale(makeVector(1.0*orients.Cols()/pc->image_size()[0], 1.0*orients.Rows()/pc->image_size()[1], 1.0)); // Invert the pose const SE3<> orig_inv = pc->pose().inverse(); orients.Fill(vert_axis); for (ManhattanBuilding::ConstCnrIt left_cnr = soln.cnrs.begin(); successor(left_cnr) != soln.cnrs.end(); left_cnr++) { ManhattanBuilding::ConstCnrIt right_cnr = successor(left_cnr); //TITLE("Next corner"); int axis = OtherHorizAxis(left_cnr->right_axis); // Compute vertices in the 3D camera frame Vec3 bl = FloorPoint(left_cnr->right_floor, floor_z); Vec3 br = FloorPoint(right_cnr->left_floor, floor_z); Vec3 tl = CeilPoint(left_cnr->right_ceil, bl); Vec3 tr = CeilPoint(right_cnr->left_ceil, br); if (bl[2] < 0) { bl = -bl; br = -br; tl = -tl; tr = -tr; } // Compute vertices in the 3D global frame Vec3 world_tl = orig_inv * tl; Vec3 world_tr = orig_inv * tr; Vec3 world_bl = orig_inv * bl; Vec3 world_br = orig_inv * br; // Compute the wall corners in the other camera Vec3 ret_tl = new_pose * world_tl; Vec3 ret_tr = new_pose * world_tr; Vec3 ret_bl = new_pose * world_bl; Vec3 ret_br = new_pose * world_br; ClipToFront(ret_tr, ret_tl); ClipToFront(ret_br, ret_bl); // Compute the wall corners in the other image Vec3 im_tl = pc->RetToIm(ret_tl); Vec3 im_tr = pc->RetToIm(ret_tr); Vec3 im_bl = pc->RetToIm(ret_bl); Vec3 im_br = pc->RetToIm(ret_br); // Build the polygon and fill vector<Vec3 > poly; poly.push_back(im_tl); poly.push_back(im_bl); poly.push_back(im_br); poly.push_back(im_tr); FillPolygon(poly, orients, axis); } }
int Delete(tree**root,int n) { tree **node,*temp,*next,*parent; (node)=search(root,n); temp=*node; if(temp==NULL) return 0; if(temp->right==NULL && temp->left==NULL) { if(temp->par->right==temp) temp->par->right==NULL; else (*node)->par->left==NULL; } else { next=successor((*node)); (*node)->data=next->data; while(next->right!=NULL && next->left!=NULL) next=successor((*node)); Delete(root,next->data); } return 0; }
Mapiter<S,T> Map<S,T>::lub (const S& s) const { Mapnode_ATTLC<S,T>* t = head(); while(t){ if(s < t->map_data.key){ if(t->L()) t = t->L(); else break; } else if(t->map_data.key < s){ if(t->R()) t = t->R(); else { t = successor(t); break; } } else break; } while (t && t->remove_mark){ t = successor(t); } if(t) return Mapiter<S,T> (this, t); else return Mapiter<S,T> (this, 0); }
const MatD& MonocularManhattanBnb::ComputeDepthMap(double zfloor, double zceil) { // Configure and clear the depth renderer depth_renderer.Configure(*pc); depth_renderer.RenderInfinitePlane(zfloor, kVerticalAxis); depth_renderer.RenderInfinitePlane(zceil, kVerticalAxis); // Invert the pose int i = 0; const SE3<> inv = pc->pose().inverse(); for (ManhattanBuilding::ConstCnrIt left_cnr = soln.cnrs.begin(); successor(left_cnr) != soln.cnrs.end(); left_cnr++) { ManhattanBuilding::ConstCnrIt right_cnr = successor(left_cnr); int axis = OtherHorizAxis(left_cnr->right_axis); // Compute vertices in the 3D camera frame Vec3 bl = FloorPoint(left_cnr->right_floor, zfloor); Vec3 br = FloorPoint(right_cnr->left_floor, zfloor); Vec3 tl = CeilPoint(left_cnr->right_ceil, bl); Vec3 tr = CeilPoint(right_cnr->left_ceil, br); if (bl[2] < 0) { bl = -bl; br = -br; tl = -tl; tr = -tr; } // Project into renderer depth_renderer.Render(inv*tl, inv*br, inv*tr, axis); depth_renderer.Render(inv*tl, inv*br, inv*bl, axis); } return depth_renderer.depthbuffer(); }
SplayTree::node* SplayTree::upper_bound_by_value(const void** v) const { node* n = NULL; node* v_n = node::convertToNode(v); if (find_hint(v_n, n)) { return successor(n); } else if (NULL == n) { return NULL; } else { if (-1 == compare_functor(this, n, v_n)) { return successor(n); } else { return n; } } }
int main() { for (size_t n = 0; n <= 100; ++n) { for (int i = 0; i < 1000; ++i) { const tree_node* root = random_binary_search_tree(n); for (size_t key = 0; key < n; ++key) { const tree_node* node = find(root, key); assert(node != nullptr && node->key == key); if (key == n-1) { assert(successor(node) == nullptr); } else { assert(successor(node)->key == key+1); } } delete root; } std::cout << "passed random tests for trees of size " << n << std::endl; } return 0; }
bool remove(BinarySearchTree * tree, int key) { if (search(tree, key) == NULL) { return false; } TreeNode * deleteNode = search(tree, key); if (deleteNode->left == NULL) { transplant(tree, deleteNode, deleteNode->right); } else if (deleteNode->right == NULL) { transplant(tree, deleteNode, deleteNode->left); } else { TreeNode * sucNode = successor(tree, deleteNode->key); if (sucNode->parent != deleteNode) { transplant(tree, sucNode, sucNode->right); sucNode->right = deleteNode->right; sucNode->right->parent = sucNode; } transplant(tree, deleteNode, sucNode); sucNode->left = deleteNode->left; sucNode->left->parent = sucNode; } return true; }
extern void LSQ_DeleteElement(LSQ_HandleT handle, LSQ_IntegerIndexT key) { AVLTreeT *tree = (AVLTreeT *)handle; TreeNodeT *node = NULL, *parent = NULL; IteratorT * iter = (IteratorT *)LSQ_GetElementByIndex(handle, key); int new_key; if (!LSQ_IsIteratorDereferencable(iter)) return; parent = iter->node->parent; if (iter->node->l_child == NULL && iter->node->r_child == NULL) replaceNode(tree, iter->node, NULL); else if (iter->node->l_child != NULL && iter->node->r_child != NULL) { node = successor(iter->node); new_key = node->key; iter->node->value = node->value; LSQ_DeleteElement(handle, node->key); iter->node->key = new_key; return; } else if (iter->node->l_child != NULL) replaceNode(tree, iter->node, iter->node->l_child); else if (iter->node->r_child != NULL) replaceNode(tree, iter->node, iter->node->r_child); free(iter->node); tree->size--; restoreBalance(tree, parent, BT_AFTER_DELETE); }
void btree_erase(t_btree *tree, t_btree_node *node) { t_btree_node *x; t_btree_node *to_destroy; if (node == NULL) return ; if (btree_node_is_leave(node)) to_destroy = node; else to_destroy = successor(node); if (to_destroy->left) x = to_destroy->left; else x = to_destroy->right; if (x) x->parent = to_destroy->parent; if (to_destroy->parent == NULL) tree->root = x; else { if (to_destroy == to_destroy->parent->left) to_destroy->parent->left = x; else to_destroy->parent->right = x; } cleanup(tree, node, to_destroy); }
void InterpreterRuntime::SignatureHandlerGenerator::pass_long() { Argument jni_arg(jni_offset(), false); Register Rtmp = O0; #ifdef ASSERT if (TaggedStackInterpreter) { // check at least one tag is okay Label ok; __ ld_ptr(Llocals, Interpreter::local_tag_offset_in_bytes(offset() + 1), Rtmp); __ cmp(Rtmp, G0); __ brx(Assembler::equal, false, Assembler::pt, ok); __ delayed()->nop(); __ stop("Native object has bad tag value"); __ bind(ok); } #endif // ASSERT #ifdef _LP64 __ ldx(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); __ store_long_argument(Rtmp, jni_arg); #else __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 1), Rtmp); __ store_argument(Rtmp, jni_arg); __ ld(Llocals, Interpreter::local_offset_in_bytes(offset() + 0), Rtmp); Argument successor(jni_arg.successor()); __ store_argument(Rtmp, successor); #endif }
void back() { int is,hs; level = 2; init(); while(level > 0) { hs = 1; is = 0; while(hs && !is) { hs = successor(); if( hs ) is = valid(); } if(hs) { if(solution()) {print();break;} else {level++;init();} } else level--; } }
bool successor(const Key& k, Key& suc) { BSTNode* cur = find_rec(this->root_, k); if (cur == nullptr) return false; BSTNode* suc_node = successor(cur); if (suc_node != nullptr) suc = suc_node->key_; return suc_node != nullptr; }
struct rb_node *tree_delete(struct redblack_tree *t, struct rb_node *z) { struct rb_node *y, *x; y = (z->left == nil || z->right == nil) ? z : successor(z); x = (y->left != nil) ? y->left : y->right; x->parent = y->parent; if (y->parent == nil) t->root = x; else if (y == y->parent->left) y->parent->left = x; else y->parent->right = x; if (y != z) { /* true <=> z has two children */ z->key = y->key; /* Copy y's satellite data into z */ } if (y->color == BLACK) rb_delete_fixup(t, x); t->size--; return y; }
void back() { int hs,is; level = 1; while(level > 0) { hs = 1; is = 0; while(hs && !is) { hs = successor(); if( hs ) is = valid(); } if( hs ) { if( valid() ) if(solution()) print(); else { level++; init(); } } else level--; } };
void SplayTree::insert_range(const node* n1, const node* n2) { while(n1 != n2) { insert(copy_functor(n1)); n1 = successor(n1); } }
//! Update the edge A down flag void updateEdgeADownFlag() { isEdgeADown = Geometry2D::isToTheRightOfLine( referencePoint, polygon[successor(a, nrOfPolygonPoints)], polygon[a] ); }
// Delete a node from the tree void delete_node(struct bst *T, int data) { struct node* iter; iter = search(T, data); // No such node if (iter==NULL) { printf("No such node to delete."); } else { // Leaf node if (iter->right==NULL && iter->left==NULL) { if (iter->parent!=NULL) { if (iter->parent->data<iter->data) iter->parent->right = NULL; else iter->parent->left = NULL; } } // Node with right child else if(iter->left==NULL && iter->right!=NULL) { if (iter->parent!=NULL) { iter->right->parent = iter->parent; if (iter->parent->data<iter->data) iter->parent->right = iter->right; else iter->parent->left = iter->right; } } // Node with left child else if(iter->left!=NULL && iter->right==NULL) { if (iter->parent!=NULL) { iter->left->parent = iter->parent; if (iter->parent->data<iter->data) iter->parent->right = iter->left; else iter->parent->left = iter->left; } } // Node with both children else if(iter->left!=NULL & iter->right!=NULL) { struct node *next; int next_data; next = predecessor(iter); // Find the predecessor if (next==NULL) { next = successor(iter); } if (next==NULL) { printf("Deleting the root node."); free(T->root); return; } next_data = next->data; delete_node(T, next->data); // Delete the predecessor node iter->data = next_data; // Put that in the iter's position } } }
/* * tree_delete -- * Delete the item whose key is equal to 'key' from the tree. * See section 13.4, "Introduction to Algorithms", 2/e for the * algorithm. */ void tree_delete(T tree, Key key) { assert(tree); Node *x, *y, *z; /* * find the to-be-deleted node z */ z = search(tree, key); if (z == NIL(tree)) return; /* * y is the spliced out node */ if ((z->left == NIL(tree)) || (z->right == NIL(tree))) y = z; else y = successor(tree, z); /* * Maintain the size field of each node on the path from y to the * root. */ Node *p = y->parent; while (p != NIL(tree)) { p->size--; p = p->parent; } /* * link y's only child to y's parent */ if (y->left != NIL(tree)) x = y->left; else x = y->right; x->parent = y->parent; if (y->parent == NIL(tree)) // we are deleting the root tree->root = x; else if (y == y->parent->left) y->parent->left = x; else y->parent->right = x; /* if y is not z copy satellite data */ if (y != z) z->item = y->item; /* maintain red-black property if necessary */ if (y->color == BLACK) delete_fixup(tree, x); free(y); }
/** * We define the successor function suc which takes a key k ∈ (F 82 ) 8 , a state s and * an input y ∈ F 2 and outputs the successor state s ′ . We overload the function suc * to multiple bit input x ∈ F n 2 which we define as * @param k - array containing 8 bytes **/ State suc(uint8_t* k,State s, BitstreamIn *bitstream) { if(bitsLeft(bitstream) == 0) { return s; } bool lastbit = tailBit(bitstream); return successor(k,suc(k,s,bitstream), lastbit); }
/* Prints all the data items in TREE in in-order, using an iterative algorithm. */ void pbin_traverse(const struct pbin_tree *tree) { struct pbin_node *node; assert(tree != NULL); if (tree->root != NULL) for (node = minimum(tree->root); node != NULL; node = successor(node)) printf("%d ", node->data); }
bool State::isLegal(int mover, vector<int> move){ //check whether a move of a mover is legal or not vector<vector<int> > moveList = successor(mover); vector<vector<int> >::iterator iter; for (iter = moveList.begin(); iter!=moveList.end(); iter++) { if (move[0] == iter->at(0) && move[1] == iter->at(1)) return true; } return false; }
void Btree<T>::recDelete(T& x, unsigned ptr, Boolean& found) // // // Purpose: function that performs node deletion. // // Parameters: // // input: x - the data to be removed // ptr - the // // output: // found - flag that indicates whether item x was found // { Bstruct<T> *buf, *buf2; unsigned i; if (ptr == BTREE_NIL) found = FALSE; else { buf = new Bstruct<T>; readNode(buf, ptr); // search for x in the current node found = (searchNode(x, buf, i)) ? TRUE : FALSE; // found an element that matches item x? if (found) { // does ptr point to a leaf node? if (buf->nodeLink[i - 1] == BTREE_NIL) { // remove element at index i trim(buf, i); writeNode(buf, ptr); } else { // replace data[i] with its successor in node ptr successor(buf, i); writeNode(buf, ptr); recDelete(buf->data[i], buf->nodeLink[i], found); } } else recDelete(x, buf->nodeLink[i], found); if (buf->nodeLink[i] != BTREE_NIL) { buf2 = new Bstruct<T>; readNode(buf2, buf->nodeLink[i]); if (buf2->count < BTREE_MIN) { restore(buf, i); writeNode(buf, ptr); } delete buf2; } delete buf; } }
qreal RoutingInstruction::distanceToEnd() const { qreal result = distance(); const RoutingInstruction* i = successor(); while ( i ) { result += i->distance(); i = i->successor(); } return result; }
rbnode* rbnode_next(rbnode *n) { if(!n) return NULL; rbtree_t rb = n->tree; rbnode *succ = successor(rb,n); if(succ == rb->nil) return NULL; return succ; }
bool RBTree<T>::remove(T key) { bool found = true; pTreeNode<pair<bool, T> >* foundNode = BinSearch(key, this->root); // if the tree is empty or the data is not found if (!(foundNode && foundNode->getData() == key)) { found = false; } else // remove by successor { pTreeNode<pair<bool, T> >* heir = successor(foundNode); pTreeNode<pair<bool, T> >* child = NULL == heir->right ? heir->left : heir->right; pTreeNode<pair<bool, T> >* parent = heir->parent; bool childIsLeft = true; foundNode->injectData(heir->getData()); // detach child from heir (if child exists) if (NULL != child) // at least 1 child { child->parent = parent; } if (NULL == parent) // if heir is the root { this->root = child; if (NULL != this->root) { isBlack(this->root) = true; } } else { childIsLeft = heir == parent->left; if (true == childIsLeft) { parent->left = child; } else { parent->right = child; } if (true == isBlack(heir)) { // child could be null, so parent is passed in deleteFixUp(parent, childIsLeft); } } delete heir; } return found; }
/* ============================================================================= * rbtree_verify * ============================================================================= */ long rbtree_verify (rbtree_t* s, long verbose) { node_t* root = s->root; if (root == NULL) { return 1; } if (verbose) { printf("Integrity check: "); } if (root->p != NULL) { printf(" (WARNING) root %lX parent=%lX\n", (unsigned long)root, (unsigned long)root->p); return -1; } if (root->c != BLACK) { printf(" (WARNING) root %lX color=%lX\n", (unsigned long)root, (unsigned long)root->c); } /* Weak check of binary-tree property */ long ctr = 0; node_t* its = firstEntry(s); long int (*compare)(const void*, const void*) = s->compare->compare_notm; while (its != NULL) { ctr++; node_t* child = its->l; if (child != NULL && child->p != its) { printf("Bad parent\n"); } child = its->r; if (child != NULL && child->p != its) { printf("Bad parent\n"); } node_t* nxt = successor(its); if (nxt == NULL) { break; } if (compare(its->k, nxt->k) >= 0) { printf("Key order %lX (%ld %ld) %lX (%ld %ld)\n", (unsigned long)its, (long)its->k, (long)its->v, (unsigned long)nxt, (long)nxt->k, (long)nxt->v); return -3; } its = nxt; } long vfy = verifyRedBlack(root, 0); if (verbose) { printf(" Nodes=%ld Depth=%ld\n", ctr, vfy); } return vfy; }
inline std::vector<T> printBSTree2() const//use successor function { std::vector<T> res; auto p = minimumPtr(root); while (p) { res.push_back(p->key); p = successor(p); } return res; }
/* Returns the element after ELEM in its rbtree. If ELEM is the last element in its rbtree, returns the rbtree tail. Results are undefined if ELEM is itself a rbtree tail. */ struct rbtree_elem * rbtree_next (struct rbtree_elem const *elem) { struct rbtree_elem *next; next = successor(elem); if (next == nil) { return NULL; } else { return next; } }
/** Gets the number of free sectors after a given child Partition in this PartitionTable. @param p the Partition for which to get the free sectors after @returns the number of free sectors after the Partition */ qint64 PartitionTable::freeSectorsAfter(const Partition& p) const { const Partition* succ = successor(p); // due to the space required for extended boot records the // below is NOT the same as succ->length() if (succ && succ->roles().has(PartitionRole::Unallocated)) return succ->lastSector() - p.lastSector(); return 0; }
void SplayTree::clear() { node* n = front(); while(n) { node* temp = n; n = successor(n); remove(temp); delete_functor(temp); } }