Mapiter<S,T> Map<S,T>::glb (const S& s) const { Mapnode_ATTLC<S,T>* t = head(); while(t){ if(t->map_data.key < s){ if(t->R()) t = t->R(); else break; } else if (s < t->map_data.key){ if(t->L()) t = t->L(); else { t = predecessor(t); break; } } else break; } while (t && t->remove_mark){ t = predecessor(t); } if(t) return Mapiter<S,T> (this, t); else return Mapiter<S,T> (this, 0); }
int main(void) { TreeNode *root = insert("Testing 123", NULL); root = insert("testing", root); insert("Smaller", root); //printInorder(root); insert("Smaller", root); /* if (find("Smaller", root)) printf("YES.\n"); else printf("NO :(\n"); printInorderReverse(root); TreeNode *temp = successor("Testing 123", root); printf("%s\n", temp -> element);*/ insert("Even Smaller", root); insert("tester", root); /*printInorder(root); delete("Testing 123", root); printInorder(root);*/ TreeNode *tmp = predecessor("Smaller", root); printf("%s\n", tmp -> element); freeTree(root); return 0; } // main
void PolyhedronShortestPath(Polyhedron& P, vertex_descriptor &a, vertex_descriptor &b, HalfedgeVector &hv) { // create indices, predecessor and distance map VertexIdPMap vertex_index_pmap = get(boost::vertex_index, P); std::vector<vertex_descriptor> predecessor(boost::num_vertices(P)); PredecessorPMap predecessor_pmap = PredecessorPMap(predecessor.begin(), vertex_index_pmap); std::vector<double> distance(boost::num_vertices(P)); DistancePMap distance_pmap = DistancePMap(distance.begin(), vertex_index_pmap); // boost: set weights as edge length (default weight is squared length between vertices) std::map<edge_descriptor, double> edge2weight; WeightAPMap weight_apmap = WeightAPMap(edge2weight); edge_iterator ei, ei_end; for(boost::tie(ei,ei_end)=boost::edges(P); ei!=ei_end; ++ei) edge2weight.insert(make_pair(*ei,(*ei).opposite().halfedge()->weight())); // opposite: we compute from b to a // run dijkstra boost::detail::dijkstra_dispatch2(P, b, distance_pmap, weight_apmap, vertex_index_pmap, distance_map(distance_pmap).predecessor_map(predecessor_pmap)); // extract edges vertex_descriptor v = a; for(vertex_descriptor u = predecessor_pmap[v]; u!=v; v=u, u=predecessor_pmap[v]) hv.push_back(GetHalfedge(v,u)); }
bool predecessor(const Key& k, Key& pre) { BSTNode* cur = find_rec(this->root_, k); if (cur == nullptr) return false; BSTNode* pre_node = predecessor(cur); if (pre_node != nullptr) pre = pre_node->key_; return pre_node != nullptr; }
/* 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; }
// 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 } } }
int main(int argc,char* argv[]) { const char* filename = (argc > 1) ? argv[1] : "data/points.xy"; std::ifstream input(filename); Triangulation t; Filter is_finite(t); Finite_triangulation ft(t, is_finite, is_finite); Point p ; while(input >> p){ t.insert(p); } vertex_iterator vit, ve; // Associate indices to the vertices int index = 0; // boost::tie assigns the first and second element of the std::pair // returned by boost::vertices to the variables vit and ve for(boost::tie(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ){ vertex_descriptor vd = *vit; vertex_id_map[vd]= index++; } // Dijkstra's shortest path needs property maps for the predecessor and distance // We first declare a vector std::vector<vertex_descriptor> predecessor(boost::num_vertices(ft)); // and then turn it into a property map boost::iterator_property_map<std::vector<vertex_descriptor>::iterator, VertexIdPropertyMap> predecessor_pmap(predecessor.begin(), vertex_index_pmap); std::vector<double> distance(boost::num_vertices(ft)); boost::iterator_property_map<std::vector<double>::iterator, VertexIdPropertyMap> distance_pmap(distance.begin(), vertex_index_pmap); // start at an arbitrary vertex vertex_descriptor source = *boost::vertices(ft).first; std::cout << "\nStart dijkstra_shortest_paths at " << source->point() <<"\n"; boost::dijkstra_shortest_paths(ft, source, distance_map(distance_pmap) .predecessor_map(predecessor_pmap) .vertex_index_map(vertex_index_pmap)); for(boost::tie(vit,ve)=boost::vertices(ft); vit!=ve; ++vit ){ vertex_descriptor vd = *vit; std::cout << vd->point() << " [" << vertex_id_map[vd] << "] "; std::cout << " has distance = " << boost::get(distance_pmap,vd) << " and predecessor "; vd = boost::get(predecessor_pmap,vd); std::cout << vd->point() << " [" << vertex_id_map[vd] << "]\n "; } return 0; }
bool remove(const T key) { if(key == value) return false; // cannot remove parent from self if(key < value) { if(left == NULL) return false; if(left->getValue() == key) { BinarySearchTree<T> *ls = left->leftNode(); BinarySearchTree<T> *rs = left->rightNode(); if(ls == NULL && rs == NULL) { left = NULL; } else if(ls == NULL) { left = rs; } else if(rs == NULL) { left = ls; } else { BinarySearchTree<T> *pred = predecessor(left); left->setValue(pred->getValue()); return left->rightNode()->remove(pred->getValue()); } return true; } else { return left->remove(key); } } else { if(right == NULL) return false; if(right->getValue() == key) { BinarySearchTree<T> *ls = right->leftNode(); BinarySearchTree<T> *rs = right->rightNode(); if(ls == NULL && rs == NULL) { right = NULL; } else if(ls == NULL) { right = rs; } else if(rs == NULL) { right = ls; } else { BinarySearchTree<T> *pred = predecessor(right); right->setValue(pred->getValue()); return right->rightNode()->remove(pred->getValue()); } return true; } else { return right->remove(key); } } }
qreal RoutingInstruction::distanceFromStart() const { qreal result = 0.0; const RoutingInstruction* i = predecessor(); while ( i ) { result += i->distance(); i = i->predecessor(); } return result; }
rbnode* rbnode_pre(rbnode*n) { if(!n) return NULL; rbtree_t rb = n->tree; rbnode *presucc = predecessor(rb,n); if(presucc == rb->nil) return NULL; return presucc; }
/** Gets the number of free sectors before a given child Partition in this PartitionTable. @param p the Partition for which to get the free sectors before @returns the number of free sectors before the Partition */ qint64 PartitionTable::freeSectorsBefore(const Partition& p) const { const Partition* pred = predecessor(p); // due to the space required for extended boot records the // below is NOT the same as pred->length() if (pred && pred->roles().has(PartitionRole::Unallocated)) return p.firstSector() - pred->firstSector(); return 0; }
inline std::vector<T> printBSTree3() const///use predecessor function { std::vector<T> res; auto p = maximumPtr(root); while (p) { res.push_back(p->key); p = predecessor(p); } std::reverse(res.begin(), res.end()); return res; }
/* Returns the element before ELEM in its rbtree. If ELEM is the first element in its rbtree, returns NULL. */ struct rbtree_elem * rbtree_prev (struct rbtree_elem const *elem) { struct rbtree_elem *pred; ASSERT(elem != NULL); pred = predecessor(elem); if (pred == nil) { return NULL; } else { return pred; } }
//! Check if the c-th polygon point is the left most tangent point bool isPointCLeftMostTangentPoint() { return ( !Geometry2D::isToTheRightOfLine( referencePoint, polygon[predecessor(c, nrOfPolygonPoints)], polygon[c] ) && ( !isEdgeCDown ) ); }
void printPredecessors(node* root) { if (!root) return; printPredecessors(root->left); node* prev = predecessor(root); cout << "{" << root->data << ":" << (prev ? prev->data : -1) << "} "; printPredecessors(root->right); }
QString RoutingInstruction::nextRoadInstruction() const { if ( roadType() == "roundabout" ) { return QObject::tr( "Enter the roundabout." ); } if ( roadType() == "motorway_link" ) { QStringList motorways = QStringList() << "motorway" << "motorway_link"; bool const leaving = predecessor() && motorways.contains( predecessor()->roadType() ); if ( leaving ) { if ( roadName().isEmpty() ) { return QObject::tr( "Take the exit." ); } else { return QObject::tr( "Take the exit towards %1." ).arg( roadName() ); } } if ( roadName().isEmpty() ) { return QObject::tr( "Take the ramp." ); } else { return QObject::tr( "Take the ramp towards %1." ).arg( roadName() ); } } TurnType turnType = m_turnType; if ( predecessor() && predecessor()->roundaboutExitNumber() ) { switch ( predecessor()->roundaboutExitNumber() ) { case 1: turnType = RoundaboutFirstExit; break; case 2: turnType = RoundaboutSecondExit; break; case 3: turnType = RoundaboutThirdExit; break; } } return generateRoadInstruction( turnType, roadName() ); }
static int bstree_node_remove( bstree bst, unsigned int *node, KEYTYPE key, VALUETYPE *value){ unsigned int swap_node; VALUETYPE tmp; if( *node == NODE_NULL ){ return BSTREE_FAILURE; } if( key == bst->array[*node].key){ *value = bst->array[*node].value; status = BSTREE_SUCCESS; if( bst->array[*node].left == NODE_NULL && bst->array[*node].right == NODE_NULL ){ *node = NODE_NULL; bst->size--; if( ((double) bst->size / (double) bst->array_size) < 0.25 && bst->array_size > MINSIZE ){ if( bstree_shrink( bst) == BSTREE_MEM_ERROR){ return BSTREE_MEM_ERROR; } } return BSTREE_SUCCESS; } if( bst->array[*node].left == NODE_NULL ){ swap_node = successor( bst, *node); bst->array[*node].key = bst->array[swap_node].key; bst->array[*node].value = bst->array[swap_node].value; bstree_node_remove( bst, bst->array[*node].right, bst->array[swap_node].key, &tmp); }else{ swap_node = predecessor( bst, *node); bst->array[*node].key = bst->array[swap_node].key; bst->array[*node].value = bst->array[swap_node].value; bstree_node_remove( bst, bst->array[*node].left, bst->array[swap_node].key, &tmp); } }else if( COMP( key, bst->array[*node].key) < 0 ){ status = bstree_node_remove( bst, &(bst->array[node].left), key, value); }else{ status = bstree_node_insert( bst, &(bst->array[node].right), key, value); } decrease_level( bst, *node); skew( bst, node); if( bst->array[*node].right != NODE_NULL ){ skew( bst, &(bst->array[*node].right)); skew( bst, &(bst->array[bst->array[*node].right].right)); } split( bst, node); split( bst, &(bst->array[*node].right)); return status; }
int main() { node* root = newnode(29); insert(root,3); insert(root,52); insert(root,12); insert(root,23); insert(root,31); insert(root,17); node* pred = predecessor(root,52); printf("%d\n",pred->value); return 0; }
extern void LSQ_RewindOneElement(LSQ_IteratorT iterator) { IteratorT * iter = (IteratorT *)iterator; if (IS_HANDLE_INVALID(iterator) || (iter->tree->size == 0)) return; if (LSQ_IsIteratorPastRear(iterator)){ iter->node = treeMaximum(iter->tree->root); iter->state = IST_DEREFERENCABLE; return; } iter->node = predecessor(iter->node); if (iter->node == NULL) iter->state = IST_BEFORE_FIRST; }
void BST::Remove(Node* z) { if(!z->lchild && !z->rchild) { if(z == root_) root_ = NULL; else if(z == z->parent->lchild) z->parent->lchild = NULL; else z->parent->rchild = NULL; } else if(z->lchild==NULL || z->rchild==NULL) { if(z == root_) { if(z->lchild) root_ = z->lchild; else root_ = z->rchild; root_->parent = NULL; } else { if(z==z->parent->lchild && z->lchild) { z->parent->lchild = z->lchild; z->lchild->parent = z->parent; } else if(z==z->parent->lchild && z->rchild) { z->parent->lchild = z->rchild; z->rchild->parent = z->parent; } else if(z==z->parent->rchild && z->lchild) { z->parent->rchild = z->lchild; z->lchild->parent = z->parent; } else { z->parent->rchild = z->rchild; z->rchild->parent = z->parent; } } } else { Node *s = predecessor(z); z->data = s->data; if(z == s->parent) s->parent->lchild = s->lchild; else s->parent->rchild = s->lchild; if(s->lchild) s->lchild->parent = s->parent; } }
//! Check if the c-th polygon point is the right most tangent point bool isPointCRightMostTangentPoint() { return ( ( isEdgeCDown || Geometry2D::areCollinear( referencePoint, polygon[successor(c, nrOfPolygonPoints)], polygon[c] ) ) && !Geometry2D::isToTheLeftOfLine( referencePoint, polygon[predecessor(c, nrOfPolygonPoints)], polygon[c] ) ); }
/* 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); }
void CurvatureDetector::computeGraph(const LaserReading& reading, std::vector<Point2D>& graphPoints, Graph& graph, std::vector<unsigned int>& maxRangeMapping) const { const std::vector<Point2D>& worldPoints = reading.getWorldCartesian(); graphPoints.reserve(worldPoints.size()); std::vector<GraphEdge> edges; std::vector< boost::property < boost::edge_weight_t, double > > weights; edges.reserve(worldPoints.size()*worldPoints.size()); weights.reserve(worldPoints.size()*worldPoints.size()); unsigned int currentVertexNumber = 0; for(unsigned int i = 0; i < worldPoints.size(); i++){ if(m_useMaxRange || reading.getRho()[i] < reading.getMaxRange()){ graphPoints.push_back(worldPoints[i]); maxRangeMapping.push_back(i); unsigned int targetVertexNumber = currentVertexNumber + 1; for(unsigned int j = i + 1; j < worldPoints.size(); j++){ if(m_useMaxRange || reading.getRho()[j] < reading.getMaxRange()){ Point2D difference = worldPoints[i] - worldPoints[j]; double weight = hypot(difference.x, difference.y); edges.push_back(GraphEdge(currentVertexNumber,targetVertexNumber)); weights.push_back(weight); targetVertexNumber++; } } currentVertexNumber++; } } MatrixGraph costGraph(currentVertexNumber); for(unsigned int i = 0; i < edges.size(); i++){ boost::add_edge(edges[i].first, edges[i].second, weights[i], costGraph); } boost::remove_edge(0, currentVertexNumber - 1, costGraph); for(unsigned int iter = 0; iter <= m_dmst; iter++){ std::vector < boost::graph_traits < Graph >::vertex_descriptor > predecessor(boost::num_vertices(costGraph)); boost::prim_minimum_spanning_tree(costGraph, &predecessor[0]); for(unsigned int i = 1; i < predecessor.size(); i++){ boost::add_edge(predecessor[i], i, boost::get(boost::edge_weight, costGraph, boost::edge(predecessor[i], i, costGraph).first), graph); boost::remove_edge(predecessor[i], i, costGraph); } } }
static struct rbtree_elem * find_first_equal_entry(struct rbtree const *tree, struct rbtree_elem const *elem, struct rbtree_elem *root) { while (1) { struct rbtree_elem *pred; pred = predecessor(root); if (pred == nil || tree->less(pred, elem, tree->aux)) { break; } ASSERT( !tree->less(pred, elem, tree->aux) && !tree->less(elem, pred, tree->aux)); root = pred; } ASSERT(root != nil); ASSERT( !tree->less(elem, root, tree->aux) && !tree->less(root, elem, tree->aux)); return root; }
tree_node* tree_delete(tree_node* root, int key) { tree_node *newNode; // case a: the key is in a leaf, delete the key directly. if(root->leaf == 1) newNode = delete_from_leaf(root, key); else { int i = 0; while((i < root->keynum)&&(root->key[i] < key)) i++; //case b: when the key in an internal node, if its left child's or // right child's keynum > 1, delete the node's predecessor or successor. // otherwise, merge two children. if((i < root->keynum)&&(root->key[i] == key)) { if(root->children[i]->keynum > 1) { int p = predecessor(root, i); root->key[i] = p; newNode = tree_delete(root->children[i], p); } else if(root->children[i+1]->keynum > 1) { int s = successor(root, i+1); root->key[i] = s; newNode = tree_delete(root->children[i+1], s); } else { root = merge_node(root->children[i], root, i, 1); newNode = tree_delete(root, key); } } else { //case c: the key in not in current internal node and the node which the // key is in is the offspring of the ith children of the current node. //c1: the ith child has enough keys. call tree_delete() recursively with the child. //c2: find the left or right brother who has enough keys, move one key from the parent // to the child, and move one key from brother to the parent. if both brothers have no // enough keys, merge the child with its one brother. if(root->children[i]->keynum > 1) { newNode = tree_delete(root->children[i], key); } else { tree_node *temp; if(i == 0) temp = delete_with_brother(root->children[0], root, 0, 1); else if(i == root->keynum) temp = delete_with_brother(root->children[root->keynum], root, root->keynum, 0); else { if(root->children[i-1]->keynum > 1) temp = delete_with_brother(root->children[i], root, i, 0); else temp = delete_with_brother(root->children[i], root, i, 1); } newNode = tree_delete(temp, key); } } } if(newNode->parent == NULL) root = newNode; return root; }
struct _sthread *rbt_remove(struct rbt *tree, int vruntime) { struct node *delete_node = rbt_find(tree, vruntime); struct node *y; struct node *x; struct _sthread *thread; if(delete_node == NULL){ printf("Node with vruntime = %d doesn't exist\n", vruntime); return NULL; } if (delete_node->queue->first->next != NULL) return queue_remove(delete_node->queue); if(delete_node->left == tree->nil || delete_node->right == tree->nil) y = delete_node; else { y = sucessor(tree, delete_node); if(!(y->color == RED || !black_leef(tree, y))) y = predecessor(tree, delete_node); } if (y->left != tree->nil) x = y->left; else x = y->right; x->parent = y->parent; if (y->parent == tree->nil) tree->root = x; else { if (y == y->parent->left) y->parent->left = x; else y->parent->right = x; } if(y != delete_node){ substitute(tree, delete_node, y); if (isRoot(tree, y)) tree->root = y; } if (y == tree->first){ if (y->parent == tree->nil && y->right != tree->nil) tree->first = minimum(tree, y->right); else tree->first = x->parent; } if(y->color == BLACK) delete_fixup(tree, x); treeRoot(tree); lower(tree); thread = queue_remove(y->queue); destroy_node(y); return thread; }
OutputIterator ch_bykat_with_threshold(InputIterator first, InputIterator last, OutputIterator result, const Traits& ch_traits) { typedef typename Traits::Point_2 Point_2; typedef typename Traits::Left_turn_2 Left_turn_2; typedef typename Traits::Less_signed_distance_to_line_2 Less_dist; typedef typename std::vector< Point_2 >::iterator PointIterator; typedef typename Traits::Equal_2 Equal_2; Equal_2 equal_points = ch_traits.equal_2_object(); if (first == last) return result; std::vector< Point_2 > P; // points in subsets std::vector< Point_2 > H; // right endpoints of subproblems P.reserve(16); H.reserve(16); std::vector< PointIterator > L; // start of subset range std::vector< PointIterator > R; // end of subset range L.reserve(16); R.reserve(16); PointIterator l; PointIterator r; Point_2 a,b,c; PointIterator Pbegin, Pend; P.push_back(Point_2() ); std::copy(first,last,std::back_inserter(P)); P.push_back(Point_2() ); Pbegin = successor(P.begin()); Pend = predecessor(P.end()); ch_we_point(Pbegin, Pend, l, r, ch_traits); a = *l; b = *r; if (equal_points(a,b)) { *result = a; ++result; return result; } #if defined(CGAL_CH_NO_POSTCONDITIONS) || defined(CGAL_NO_POSTCONDITIONS) \ || defined(NDEBUG) OutputIterator res(result); #else Tee_for_output_iterator<OutputIterator,Point_2> res(result); #endif // no postconditions ... H.push_back( a ); L.push_back( Pbegin ); Left_turn_2 left_turn = ch_traits.left_turn_2_object(); R.push_back( l = std::partition( Pbegin, Pend, bind_1(bind_1(left_turn, a), b) ) ); r = std::partition( l, Pend, bind_1(bind_1(left_turn,b),a) ); Less_dist less_dist = ch_traits.less_signed_distance_to_line_2_object(); for (;;) { if ( l != r) { if ( r-l > CGAL_ch_THRESHOLD ) { c = *std::min_element( l, r, bind_1(bind_1(less_dist, a), b)); H.push_back( b ); L.push_back( l ); R.push_back( l = std::partition(l, r, bind_1(bind_1(left_turn, b), c)) ); r = std::partition(l, r, bind_1(bind_1(left_turn, c), a)); b = c; } else { std::swap( a, *--l); std::swap( b, *++r); if ( ch_traits.less_xy_2_object()(*l,*r) ) { std::sort(successor(l), r, ch_traits.less_xy_2_object() ); } else { std::sort(successor(l), r, swap_1(ch_traits.less_xy_2_object()) ); } ch__ref_graham_andrew_scan(l, successor(r), res, ch_traits); std::swap( a, *l); std::swap( b, *r); if ( L.empty() ) break; a = b; b = H.back(); H.pop_back(); l = L.back(); L.pop_back(); r = R.back(); R.pop_back(); } } else { *res = a; ++res; if ( L.empty() ) break; a = b; b = H.back(); H.pop_back(); l = L.back(); L.pop_back(); r = R.back(); R.pop_back(); } } CGAL_ch_postcondition( \ is_ccw_strongly_convex_2( res.output_so_far_begin(), \ res.output_so_far_end(), \ ch_traits)); CGAL_ch_expensive_postcondition( \ ch_brute_force_check_2( \ Pbegin, Pend, \ res.output_so_far_begin(), res.output_so_far_end(), \ ch_traits)); #if defined(CGAL_CH_NO_POSTCONDITIONS) || defined(CGAL_NO_POSTCONDITIONS) \ || defined(NDEBUG) return res; #else return res.to_output_iterator(); #endif // no postconditions ... }
void Tree::deleteNode(int key) { // Find the node. Node* thisKey = findNode(key, root); MTPD("Tree::deleteNode found node: %d\n", thisKey); MTPD("handle: %d\n", thisKey->Mtpid()); if (thisKey == root) { if (thisKey->Right()) { root = thisKey->Right(); root->setParent(NULL); return; } if (thisKey->Left()) { root = thisKey->Left(); root->setParent(NULL); return; } root = NULL; delete thisKey; return; } if ( thisKey->Left() == NULL && thisKey->Right() == NULL ) { if ( thisKey->Mtpid() > thisKey->Parent()->Mtpid() ) { thisKey->Parent()->setRight(NULL); } else { thisKey->Parent()->setLeft(NULL); } delete thisKey; return; } if ( thisKey->Left() == NULL && thisKey->Right() != NULL ) { if ( thisKey->Mtpid() > thisKey->Parent()->Mtpid() ) thisKey->Parent()->setRight(thisKey->Right()); else thisKey->Parent()->setLeft(thisKey->Right()); thisKey->Right()->setParent(thisKey->Parent()); delete thisKey; return; } if ( thisKey->Left() != NULL && thisKey->Right() == NULL ) { if ( thisKey->Mtpid() > thisKey->Parent()->Mtpid() ) thisKey->Parent()->setRight(thisKey->Left()); else thisKey->Parent()->setLeft(thisKey->Left()); thisKey->Left()->setParent(thisKey->Parent()); delete thisKey; return; } if ( thisKey->Left() != NULL && thisKey->Right() != NULL ) { Node* sub = predecessor(thisKey->Mtpid(), thisKey); if ( sub == NULL ) sub = successor(thisKey->Mtpid(), thisKey); if ( sub->Parent()->Mtpid() <= sub->Mtpid() ) sub->Parent()->setRight(sub->Right()); else sub->Parent()->setLeft(sub->Left()); thisKey->setMtpid(sub->Mtpid()); delete sub; return; } }
void SplayTree::remove(node* n) { // Fix up left-most and right-most node pointers if deleting // them. We'll fix up the root in the node removal itself. if (unlikely(header.child[LEFT] == n)) { header.child[LEFT] = successor(n); } if (unlikely(header.child[RIGHT] == n)) { header.child[RIGHT] = predecessor(n); } // Decrement size count. (header_n()->data)--; // Find node to splice out of the tree. // If n has one or no child, splice itself out, otherwise the // successor. node* y = ((!n->child[LEFT]) || (!n->child[RIGHT])) ? n : successor(n); // Find the subtree of y and link it with y's parent. node* x = y->child[LEFT] ? y->child[LEFT] : y->child[RIGHT]; if (likely(NULL != x)) { x->parent = y->parent; } if (unlikely(!y->parent)) { // Fix root. header.parent = x; } else { y->parent->child[direction(y->parent, y)] = x; } // Replace n with y. if (likely(y != n)) { y->parent = n->parent; if (y->parent) { y->parent->child[direction(y->parent, n)] = y; } else { // Removing root, so update header. header.parent = y; } y->child[LEFT] = n->child[LEFT]; if (y->child[LEFT]) { y->child[LEFT]->parent = y; } y->child[RIGHT] = n->child[RIGHT]; if (y->child[RIGHT]) { y->child[RIGHT]->parent = y; } // Splay y up to the root. splay(y); } }
tag::simd_(tag::arithmetic_,Extension),Info> { template<class Sig> struct result; template<class This,class A0> struct result<This(A0)> : meta::strip<A0>{};// NT2_FUNCTOR_CALL_DISPATCH( 1, typename nt2::meta::scalar_of<A0>::type, (2, (real_,arithmetic_)) ) NT2_FUNCTOR_CALL_EVAL_IF(1, real_) { const A0 x = abs(a0); // return sel(iseq(x, Inf<A0>()), x, successor(x)-x); A0 xp = predecessor(x); return sel(is_equal(x, Inf<A0>()), xp-predecessor(xp), x - xp); } NT2_FUNCTOR_CALL_EVAL_IF(1, arithmetic_) { details::ignore_unused(a0); return One<A0>(); } }; } } #endif