/* * sets the supported operational attributes (if required) */ int ldbm_back_operational( BackendDB *be, Connection *conn, Operation *op, Entry *e, AttributeName *attrs, int opattrs, Attribute **a ) { Attribute **aa = a; assert( e ); if ( opattrs || ad_inlist( slap_schema.si_ad_hasSubordinates, attrs ) ) { int hs; hs = has_children( be, e ); *aa = slap_operational_hasSubordinate( hs ); if ( *aa != NULL ) { aa = &(*aa)->a_next; } } return 0; }
void item::remove() { while(has_children()) { first_child_item->remove(); } data->self_refs.erase(relation_ptr->get_name()); if(prev_item) prev_item->next_item=next_item; else { if(parent_item) parent_item->first_child_item=next_item; else relation_ptr->head=next_item; } if(next_item) next_item->prev_item=prev_item; else { if(parent_item) parent_item->last_child_item=prev_item; else relation_ptr->tail=prev_item; } delete this; }
void delete_min_phase_1(heap *h) { node *min = h->root; if (has_children(min)) { // Orphan all children node *first = min->child; node *curr = min->child; do { curr->parent = NULL; curr = curr->right_sibling; } while (curr != first); // If the root has siblings, first cut it out of its sibling list // and then meld sibling and children lists if (has_siblings(min)) { node *rsib = min->right_sibling; cut_from_sibling_list(min); meld(first, rsib); } // Pick the first child as the new temporary root h->root = first; } else { // Due to the early return in the top, we are guaranteed that // if min has no children, it must have siblings, so we start // by cutting it out of its sibling list. node *sib = min->right_sibling; cut_from_sibling_list(min); // Pick a sibling (arbitrary) as the new temporary root h->root = sib; } }
int count(link x) { link u = x->l, v = x->r; if (u == NULL && v == NULL) return 0; if (u != NULL && v == NULL) return count(u); if (u == NULL && v != NULL) return count(v); if (has_children(u) && !has_children(v)) return 1 + count(u); if (has_children(v) && !has_children(u)) return 1 + count(v); return count(u) + count(v); }
/// Was the event on the 'collapse' button? /// int Fl_Tree_Item::event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const { if ( _visible && _active && has_children() && prefs.showcollapse() ) { return(event_inside(_collapse_xywh) ? 1 : 0); } else { return(0); } }
Node* Node::get_last_child() { if (has_children()) { return child(num_children() - 1)->get_last_child(); } return this; }
void MultiGrid::element_to_be_erased(TElem* elem) { // we have to remove the elements children as well. if(has_children(elem)){ get_info(elem).unregister_from_children(*this); } // we have to remove the associated info object release_child_info(elem); }
QuadTree::~QuadTree(){ delete bodies; if(has_children()) { for(QuadTree * t : children) { delete t; } } if(_remove_bodies_list != nullptr) delete _remove_bodies_list; }
grid_octree_node* grid_octree_node:: get_child_at_index(const size_t& index) { if(!has_children() || index > 8) { return nullptr; } return child_nodes_[index]; }
void get_paths(QStringList paths){ QString str; foreach(str, paths){ if(has_children(str)){ get_paths(get_absolute_dir_paths(str)); store_paths(get_absolute_file_paths(str)); } } }
/*! \brief Determines if the config context is empty. \return Returns dmz::True if the config context has no attributes and no children. Also returns dmz::True if the config context is NULL. */ dmz::Boolean dmz::Config::is_empty () const { Boolean result (True); if (_state.context) { if (_state.context->attrTable.get_count ()) { result = False; } else { result = !has_children (); } } return result; }
/*! \brief Adds the children from a config context. \details This function is equivalent to iterating through \a Data's children and adding them one at a time. \param[in] Data Config containing config context of which its children will be added. \return Returns dmz::True if the children were added. */ dmz::Boolean dmz::Config::add_children (const Config &Data) { if (_state.context && _state.context->Name) { ConfigIterator it; Config cd; while (Data.get_next_config (it, cd)) { add_config (cd); } } return has_children (); }
node* delete_min(heap *h) { // In the special case where the heap root has no siblings and no // children, we can simply null the root, decrease the size, and // return early, as no complicated work is required. node *min = h->root; if (!has_children(min) && !has_siblings(min)) { h->root = NULL; h->size -= 1; return min; } // Step 1: Remove minimum node (min) // If min has children, they are orphaned. If min also has siblings, // min is cut out from the sibling list, which is then combined with // the children list. // If min has siblings but no children, it is just cut out from the // sibling list. delete_min_phase_1(h); // Step 2: Link roots of same rank/degree // We use an array to keep track of the last seen root of each rank, // and link roots whenever we get a collision. The node that remains // a root gets a promotion (rank++), and is attempted inserted into // its new place in the array, where we again link in case of a new // collision, and so on. // To make sure the root pointer in the heap continues to point to // an actual root, we update it to point to the "link winner" every // time we link. // Because the initial root may not remain as such, we also have to // keep track of an "end" node, i.e. the right-most (last) node in // the sibling list of the root (its left sibling), starting from // the initial root itself. // In the linking step, the "loser" (the root with the highest key // value) is cut out of its sibling list, and combined with the // children list of the "winner". delete_min_phase_2(h); // Step 3: Find new min // We simply iterate over all root nodes, updating the root pointer // of the heap every time we find a smaller key delete_min_phase_3(h); // Finally, decrease heap size, and return the extracted min node h->size -= 1; return min; }
/* * sets *hasSubordinates to LDAP_COMPARE_TRUE/LDAP_COMPARE_FALSE * if the entry has children or not. */ int ldbm_back_hasSubordinates( BackendDB *be, Connection *conn, Operation *op, Entry *e, int *hasSubordinates ) { if ( has_children( be, e ) ) { *hasSubordinates = LDAP_COMPARE_TRUE; } else { *hasSubordinates = LDAP_COMPARE_FALSE; } return 0; }
bool QuadTree::insert(Body* b){ // Ignore objects which do not belong in this quad tree if (!boundary.containsPoint(b->position)){ return false; } if (!has_children() && bodies->size() < QT_NODE_CAPACITY){ // std::cout << "adding " << b << std::endl; //node_b.position = b->position; bodies->push_back(b); return true; } if( northWest == nullptr ){ subdivide(); } bool inserted = false; for(QuadTree * child : children) { if(child->insert(b)) { inserted = true; break; } } add_body(b); while(!bodies->empty()){ b = bodies->back(); bodies->pop_back(); //node_mass+=b.mass; add_body(b); for(QuadTree * child : children) { if(child->insert(b)) { inserted = true; break; } } } if(inserted) return true; // Otherwise, the point cannot be inserted for some unknown reason (which should never happen) return false; }
bool QuadTree::print_tree(int depth){ for(int i = 0 ; i < depth ; ++i){ std::cout << "\t"; } if(!has_children()){ if(bodies->size() != 0){ for(std::vector<Body*>::iterator it = bodies->begin() ; it != bodies->end() ; ++it){ std::cout << **it ; } std::cout << std::endl; }else{std::cout << "Empty leaf" << std::endl;} return true; } std::cout << "Empty node " << node_b.mass << " x: " << node_b.position.x << " y: " << node_b.position.y << std::endl; depth++; northWest->print_tree(depth +1); northEast->print_tree(depth +1); southWest->print_tree(depth +1); southEast->print_tree(depth +1); return true; }
int QuadTree::_update(Body ** removed_bodies) { int index = 0; if(!has_children()) { for(size_t i=0; i<bodies->size(); ++i) { if(!boundary.containsPoint((*bodies)[i]->position)) { remove_body((*bodies)[i]); removed_bodies[index++] = (*bodies)[i]; bodies->erase(bodies->begin() + i); } } } else if(northWest != NULL) { int empty = 0; for(QuadTree * t : children) { index += t->_update(removed_bodies + index); if(t->empty()) ++empty; } if(empty == 4) { /* All childrens are empty, delete them, so that we also become empty */ for(QuadTree * &t : children) { delete t; t = nullptr; } } for(int i=0;i<index;++i) { remove_body(removed_bodies[i]); } } else { printf("Derp\n"); abort(); } return index; }
void MultiGrid:: clear_child_connections(TElem* parent) { if(has_children(parent)) get_info(parent).unregister_from_children(*this); }
void delete_min_phase_2(heap *h) { int max_rank = (int) ceil(2 * (log(h->size + 1) / log(2.0))); node *ranks[max_rank]; for (int i = 0; i < max_rank; i++) { ranks[i] = NULL; } // The chain of root nodes is modified in the linking step, so to make // absolutely sure we go through all the root nodes, we store pointers // to them in an array, and iterate the array instead of depending on // the possibly shifty sibling list. int n = root_count(h); node **roots = (node**) malloc(n * sizeof(node*)); // Populate the array node *current = h->root; for (int i = 0; i < n; i++) { roots[i] = current; current = current->right_sibling; } // Go through each node in the array for (int i = 0; i < n; i++) { node *curr = roots[i]; // If there are pre-existing array entries, start linking while (ranks[curr->rank] != NULL) { // Determine winner and loser node *winner = (curr->key < ranks[curr->rank]->key ? curr : ranks[curr->rank]); node *loser = (curr->key < ranks[curr->rank]->key ? ranks[curr->rank] : curr); // Null the array entry right away ranks[curr->rank] = NULL; // Update loser's parent pointer and promote winner loser->parent = winner; winner->rank += 1; // Cut loser out of its sibling list, and meld with the // children list of the winner (if any, otherwise just // set the loser as the only child of the winner). cut_from_sibling_list(loser); if (has_children(winner)) { meld(winner->child, loser); } else { winner->child = loser; } // Update current to be the winner curr = winner; } // Otherwise/finally, insert current into its place in the // array, and make it the temporary heap root. ranks[curr->rank] = curr; h->root = curr; } // Free the possibly HUGE array free(roots); }
/// Draw this item and its children. void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, const Fl_Tree_Prefs &prefs, int lastchild) { if ( ! _visible ) return; fl_font(_labelfont, _labelsize); int H = _labelsize + fl_descent() + prefs.linespacing(); // Colors, fonts Fl_Color fg = _selected ? prefs.bgcolor() : _labelfgcolor; Fl_Color bg = _selected ? prefs.selectcolor() : _labelbgcolor; if ( ! _active ) { fg = fl_inactive(fg); if ( _selected ) bg = fl_inactive(bg); } // Update the xywh of this item _xywh[0] = X; _xywh[1] = Y; _xywh[2] = W; _xywh[3] = H; // Text size int textw=0, texth=0; fl_measure(_label, textw, texth, 0); int textycenter = Y+(H/2); int &icon_x = _collapse_xywh[0] = X-1; int &icon_y = _collapse_xywh[1] = textycenter - (prefs.openicon()->h()/2); int &icon_w = _collapse_xywh[2] = prefs.openicon()->w(); _collapse_xywh[3] = prefs.openicon()->h(); // Horizontal connector values int hstartx = X+icon_w/2-1; int hendx = hstartx + prefs.connectorwidth(); int hcenterx = X + icon_w + ((hendx - (X + icon_w)) / 2); // See if we should draw this item // If this item is root, and showroot() is disabled, don't draw. // char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1; if ( drawthis ) { // Draw connectors if ( prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) { // Horiz connector between center of icon and text draw_horizontal_connector(hstartx, hendx, textycenter, prefs); if ( has_children() && is_open() ) { // Small vertical line down to children draw_vertical_connector(hcenterx, textycenter, Y+H, prefs); } // Connectors for last child if ( ! is_root() ) { if ( lastchild ) { draw_vertical_connector(hstartx, Y, textycenter, prefs); } else { draw_vertical_connector(hstartx, Y, Y+H, prefs); } } } // Draw collapse icon if ( has_children() && prefs.showcollapse() ) { // Draw icon image if ( is_open() ) { prefs.closeicon()->draw(icon_x,icon_y); } else { prefs.openicon()->draw(icon_x,icon_y); } } // Background for this item int &bx = _label_xywh[0] = X+(icon_w/2-1+prefs.connectorwidth()); int &by = _label_xywh[1] = Y; int &bw = _label_xywh[2] = W-(icon_w/2-1+prefs.connectorwidth()); int &bh = _label_xywh[3] = texth; // Draw bg only if different from tree's bg if ( bg != tree->color() || is_selected() ) { if ( is_selected() ) { // Selected? Use selectbox() style fl_draw_box(prefs.selectbox(), bx, by, bw, bh, bg); } else { // Not Selected? use plain filled rectangle fl_color(bg); fl_rectf(bx, by, bw, bh); } } // Draw user icon (if any) int useroff = (icon_w/2-1+prefs.connectorwidth()); if ( usericon() ) { // Item has user icon? Use it useroff += prefs.usericonmarginleft(); usericon()->draw(X+useroff,icon_y); useroff += usericon()->w(); } else if ( prefs.usericon() ) { // Prefs has user icon? Use it useroff += prefs.usericonmarginleft(); prefs.usericon()->draw(X+useroff,icon_y); useroff += prefs.usericon()->w(); } useroff += prefs.labelmarginleft(); // Draw label if ( widget() ) { // Widget? Draw it int lx = X+useroff; int ly = by; int lw = widget()->w(); int lh = bh; if ( widget()->x() != lx || widget()->y() != ly || widget()->w() != lw || widget()->h() != lh ) { widget()->resize(lx, ly, lw, lh); // fltk will handle drawing this } } else { // No label widget? Draw text label if ( _label ) { fl_color(fg); fl_draw(_label, X+useroff, Y+H-fl_descent()-1); } } Y += H; } // end drawthis // Draw children if ( has_children() && is_open() ) { int child_x = drawthis ? // offset children to right, (hcenterx - (icon_w/2) + 1) : X; // unless didn't drawthis int child_w = W - (child_x-X); int child_y_start = Y; for ( int t=0; t<children(); t++ ) { int lchild = ((t+1)==children()) ? 1 : 0; _children[t]->draw(child_x, Y, child_w, tree, prefs, lchild); } if ( has_children() && is_open() ) { Y += prefs.openchild_marginbottom(); // offset below open child tree } if ( ! lastchild ) { draw_vertical_connector(hstartx, child_y_start, Y, prefs); } } }