ict::multivector<int> one() { ict::multivector<int> tree; ict::verify(tree); add_recursive(tree.root(), 3); ict::verify(tree); add_recursive(tree.root(), 3); ict::verify(tree); add_recursive(tree.root(), 3); ict::verify(tree); tree.root().emplace(33).emplace(34).emplace(35); int c = 4; for (auto n : {1, 2, 3}) { tree.root().emplace_back(n); auto i = tree.root().end() - 1; for (int n = 0; n < 3; ++n) { i.emplace_back(c++); auto j = i.begin() + i.size() - 1; //--j; for (int n = 0; n < 2; ++n) j.emplace_back(n); } } return tree; }
void add_recursive(char *path, char **ent, int nfil) { char **e; char *buff; int i; int item = 0; int nf; for(i=0; i<nfil; i++) { if(!is_dir(path, ent[i])) { buff = mystrcat(path,ent[i],1); if(add(&playlist_h, buff, &playlist_t)) { if(p_p == -1) p_p++; nsongs++; } free(buff); } else { // is a dir if(strncmp(ent[i], ".." ,2) != 0) { // d'oh! buff = mystrcat(path, ent[i], 1); if(e = get_dir(buff, &nf)) { add_recursive(buff, e, nf); while(item < nf) { free(e[item++]); } free(e); } free(buff); } } } }
void HierarchySaveLink::add_recursive(Model *m, kernel::ParticleIndex root, kernel::ParticleIndex p, kernel::ParticleIndexes rigid_bodies, RMF::NodeHandle cur, Data &data) { IMP_LOG_VERBOSE("Adding " << atom::Hierarchy(m, p) << std::endl); // make sure not to double add if (p != root) set_association(cur, m->get_particle(p)); data.save_static.setup_node(m, p, cur); bool local_coords = data.save_local_coordinates.setup_node(m, p, cur, rigid_bodies); bool global_coords = data.save_global_coordinates.setup_node(m, p, cur, rigid_bodies); bool static_coords = data.save_static_coordinates.setup_node(m, p, cur, rigid_bodies); IMP_INTERNAL_CHECK(!local_coords || !global_coords, "A particle can't have saved local and global coords"); do_setup_node(m, root, p, cur); if (core::RigidBody::get_is_setup(m, p)) { rigid_bodies.push_back(p); } for (unsigned int i = 0; i < atom::Hierarchy(m, p).get_number_of_children(); ++i) { kernel::ParticleIndex pc = atom::Hierarchy(m, p).get_child_index(i); RMF::NodeHandle curc = cur.add_child(get_good_name(m, pc), RMF::REPRESENTATION); add_recursive(m, root, pc, rigid_bodies, curc, data); } }
int add_recursive(Node *head) { if(head->next != 0) { return head->value + add_recursive(head->next); } else { return head->value; } }
void HierarchySaveLink::do_add(kernel::Particle *p, RMF::NodeHandle cur) { IMP_USAGE_CHECK(atom::Hierarchy(p).get_is_valid(true), "Invalid hierarchy passed."); RMF::SetCurrentFrame scf(cur.get_file(), RMF::ALL_FRAMES); data_.insert( std::make_pair(p->get_index(), boost::make_shared<Data>(cur.get_file()))); add_recursive(p->get_model(), p->get_index(), p->get_index(), ParticleIndexes(), cur, *data_[p->get_index()]); P::add_link(p, cur); data_[p->get_index()] ->save_bonds.setup_bonds(p->get_model(), p->get_index(), cur); }
static void add_recursive(GtDiagram *d, GtFeatureNode *node, GtFeatureNode* parent, GtFeatureNode *original_node) { NodeInfoElement *ni; GtFeatureNode *rep = GT_UNDEF_REPR; gt_assert(d && node && original_node); if (!parent) return; ni = nodeinfo_get(d, node); if (gt_feature_node_is_multi(original_node)) { rep = gt_feature_node_get_multi_representative(original_node); } /* end of recursion, insert into target block */ if (parent == node) { GtBlock *block ; block = nodeinfo_find_block(ni, gt_feature_node_get_type(node), rep); if (!block) { block = gt_block_new_from_node(node); nodeinfo_add_block(ni, gt_feature_node_get_type(node), rep, block); } gt_block_insert_element(block, original_node); gt_log_log("add %s to target %s", gt_feature_node_get_type(original_node), gt_block_get_type(block)); } else { /* not at target type block yet, set up reverse entry and follow */ NodeInfoElement *parent_ni; /* set up reverse entry */ ni->parent = parent; parent_ni = gt_hashmap_get(d->nodeinfo, parent); if (parent_ni) { gt_log_log("recursion: %s -> %s", gt_feature_node_get_type(node), gt_feature_node_get_type(parent)); add_recursive(d, parent, parent_ni->parent, original_node); } } }
int main(int argc, char *argv[]) { char *buff; int ch; int i; initscr(); cbreak(); noecho(); nonl(); curs_set(0); // nodelay(stdscr, TRUE); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); if((color = has_colors())) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_CYAN, COLOR_BLUE); } signal(SIGINT, cleanup); init_windows(); init_bass(); create_playlist(&playlist_h, &playlist_t); if(argc>1) { if(strncmp("/", argv[1], 1) != 0) { error("argument must be an absolute path", FALSE); } if(dirname(opendir(argv[1]))) { // is a dir if(add(&playlist_h, argv[1], &playlist_t)) { p_p++; c_p_p++; nsongs++; active_win = PLAYLIST_WIN; bass_loop = BASS_MUSIC_LOOP; play(argv[1], PLAYING_PLAYLIST); } current_path = strdup((char*)dirname(argv[1])); } else { error("argument not valid", FALSE); } } else { current_path = (char*)malloc(sizeof(char)*PATH_MAX); current_path = (char*)getcwd(current_path, PATH_MAX); } entries = refresh_browser(current_path, 0); mvprintw(0, 0, "%s", current_path); repaint_windows(); while((ch = getch()) != 'q') { switch(ch) { case 'a': // add song to playlist if(active_win == BROWSER_WIN) { if(!is_dir(current_path, entries[p_b])) { buff = mystrcat(current_path,entries[p_b],1); if(add(&playlist_h, buff, &playlist_t)) { if(p_p == -1) p_p++; nsongs++; repaint_windows(); } free(buff); } } break; case 'e': // add all songs in current dir if(active_win == BROWSER_WIN) { for(i=0; i<nfiles; i++) { if(!is_dir(current_path, entries[i])) { buff = mystrcat(current_path,entries[i],1); if(add(&playlist_h, buff, &playlist_t)) { if(p_p == -1) p_p++; nsongs++; } free(buff); } } } repaint_windows(); break; case 'c': // recursive add if(active_win == BROWSER_WIN) { //printw("---%s+++", current_path); add_recursive(current_path, entries, nfiles); repaint_windows(); //printw("---%s", current_path); } break; case 'd': // remove one song from playlist if(active_win == PLAYLIST_WIN) { if(del(&playlist_h, p_p, &playlist_t)) { nsongs--; if(p_p > nsongs - 1) { p_p = nsongs - 1; } if(p_p < c_p_p) { c_p_p--; } //stop(); repaint_windows(); } } break; case 'r': // remove all songs from playlist if(del_all(&playlist_h, &playlist_t)) { p_p = -1; c_p_p = -1; nsongs = 0; repaint_windows(); } break; case ' ': // start playback or browse filesystem case 13: //enter key if(active_win == BROWSER_WIN) { if(strcmp(entries[p_b], "..\0") == 0) { current_path = dirname(current_path); p_b = 0; entries = refresh_browser(current_path, 0); } else { if(is_dir(current_path, entries[p_b])) { current_path = dir_up(current_path, entries[p_b]); p_b = 0; entries = refresh_browser(current_path, 0); } else { buff = mystrcat(current_path,entries[p_b],1); play(buff, PLAYING_BROWSER); free(buff); c_p_p = -1; if(p_b < nfiles-1) { p_b++; } } } refresh_path(); } else { // PLAYLIST_WIN if(nsongs != 0) { play(get(&playlist_h, p_p, &playlist_t)->file, PLAYING_PLAYLIST); c_p_p = p_p; if(p_p < nsongs - 1) { p_p++; } } } repaint_windows(); break; case 's': // stop playback stop(); c_p_p = -1; repaint_windows(); clear_statusbar(NULL); break; case 'n': // next song next(); break; case 'p': // prev song prev(); break; case 'g': // go to current song p_p = c_p_p; repaint_windows(); break; case 'l': // toggle loop loop(); stop(); c_p_p = -1; repaint_windows(); break; case 'z': // toggle random random_mode(); break; case '.': // seek forward seek(1); break; case ',': // seek backward seek(-1); break; case '+': volume_up(); break; case '-': volume_down(); break; case '>': amplify_up(); break; case '<': amplify_down(); break; case KEY_UP: if(active_win == BROWSER_WIN) { if(p_b > 0) { p_b--; } } else { if(p_p > 0) { p_p--; } } repaint_windows(); break; case KEY_DOWN: if(active_win == BROWSER_WIN) { if(p_b < nfiles-1) { p_b++; } } else { if(p_p < nsongs - 1) { p_p++; } } repaint_windows(); break; case KEY_LEFT: case KEY_RIGHT: switch_activewindow(); repaint_windows(); break; case KEY_HOME: if(active_win == BROWSER_WIN) { p_b = 0; } else { if(p_p != -1) p_p = 0; } repaint_windows(); break; case KEY_END: if(active_win == BROWSER_WIN) { p_b = nfiles-1; } else { if(p_p != -1) p_p = nsongs - 1; } repaint_windows(); break; case KEY_NPAGE: if(active_win == BROWSER_WIN) { if((p_b + (browser_win->_maxy - 2)) < nfiles-1 ) { p_b += browser_win->_maxy - 1; } else { p_b = nfiles-1; } } else { if((p_p + (playlist_win->_maxy - 2)) < nsongs) { p_p += playlist_win->_maxy - 1; } else { p_p = nsongs - 1; } } repaint_windows(); break; case KEY_PPAGE: if(active_win == BROWSER_WIN) { if((p_b - (browser_win->_maxy - 2)) > 0) { p_b -= browser_win->_maxy - 1; } else { p_b = 0; } } else { if((p_p - (playlist_win->_maxy - 2)) > 0) { p_p -= playlist_win->_maxy - 1; } else { if(p_p != -1) p_p = 0; } } repaint_windows(); break; } //usleep(10); //update_status(); } cleanup(); return 0; }
void add_recursive(T x, unsigned int n) { auto y = x.emplace(n); if (n > 0) add_recursive(y, n - 1); }
static int process_node(GtDiagram *d, GtFeatureNode *node, GtFeatureNode *parent, GtError *err) { GtRange elem_range; bool *collapse; GtShouldGroupByParent *group; const char *feature_type = NULL, *parent_gft = NULL; double tmp; GtStyleQueryStatus rval; GtUword max_show_width = GT_UNDEF_UWORD, par_max_show_width = GT_UNDEF_UWORD; gt_assert(d && node); gt_log_log(">> getting '%s'", gt_feature_node_get_type(node)); /* skip pseudonodes */ if (gt_feature_node_is_pseudo(node)) return 0; feature_type = gt_feature_node_get_type(node); gt_assert(feature_type); /* discard elements that do not overlap with visible range */ elem_range = gt_genome_node_get_range((GtGenomeNode*) node); if (!gt_range_overlap(&d->range, &elem_range)) return 0; /* get maximal view widths in nucleotides to show this type */ rval = gt_style_get_num(d->style, feature_type, "max_show_width", &tmp, NULL, err); switch (rval) { case GT_STYLE_QUERY_OK: max_show_width = tmp; break; case GT_STYLE_QUERY_ERROR: return -1; break; /* should never be reached */ default: /* do not change default value */ break; } /* for non-root nodes, get maximal view with to show parent */ if (parent) { if (!gt_feature_node_is_pseudo(parent)) { parent_gft = gt_feature_node_get_type(parent); rval = gt_style_get_num(d->style, parent_gft, "max_show_width", &tmp, NULL, err); switch (rval) { case GT_STYLE_QUERY_OK: par_max_show_width = tmp; break; case GT_STYLE_QUERY_ERROR: return -1; break; /* should never be reached */ default: /* do not change default value */ break; } } else par_max_show_width = GT_UNDEF_UWORD; } /* check if this type is to be displayed at all */ if (max_show_width != GT_UNDEF_UWORD && gt_range_length(&d->range) > max_show_width) { return 0; } /* disregard parent node if it is configured not to be shown */ if (parent && par_max_show_width != GT_UNDEF_UWORD && gt_range_length(&d->range) > par_max_show_width) { parent = NULL; } /* check if this is a collapsing type, cache result */ if ((collapse = (bool*) gt_hashmap_get(d->collapsingtypes, feature_type)) == NULL) { collapse = gt_malloc(sizeof (bool)); *collapse = false; if (gt_style_get_bool(d->style, feature_type, "collapse_to_parent", collapse, NULL, err) == GT_STYLE_QUERY_ERROR) { gt_free(collapse); return -1; } gt_hashmap_add(d->collapsingtypes, (void*) feature_type, collapse); } /* check if type should be grouped by parent, cache result */ if ((group = (GtShouldGroupByParent*) gt_hashmap_get(d->groupedtypes, feature_type)) == NULL) { bool tmp; group = gt_malloc(sizeof (GtShouldGroupByParent)); rval = gt_style_get_bool(d->style, feature_type, "group_by_parent", &tmp, NULL, err); switch (rval) { case GT_STYLE_QUERY_OK: if (tmp) *group = GT_GROUP_BY_PARENT; else *group = GT_DO_NOT_GROUP_BY_PARENT; break; case GT_STYLE_QUERY_NOT_SET: *group = GT_UNDEFINED_GROUPING; break; case GT_STYLE_QUERY_ERROR: gt_free(group); return -1; break; /* should never be reached */ } gt_hashmap_add(d->groupedtypes, (void*) feature_type, group); } /* decide where to place this feature: */ if (*collapse) { /* user has specified collapsing to parent for this type */ if (parent && !gt_feature_node_is_pseudo(parent)) { /* collapsing child nodes are added to upwards blocks, but never collapse into pseudo nodes */ add_recursive(d, node, parent, node); } else { /* if no parent or only pseudo-parent, do not collapse */ if (add_to_current(d, node, parent, err) < 0) { return -1; } } } else /* (!*collapse) */ { if (parent) { bool do_not_overlap = false; do_not_overlap = gt_feature_node_direct_children_do_not_overlap_st(parent, node); if (*group == GT_GROUP_BY_PARENT || (do_not_overlap && *group == GT_UNDEFINED_GROUPING)) { if (gt_feature_node_is_pseudo(parent) && gt_feature_node_is_multi(node)) { if (add_to_rep(d, node, parent, err) < 0) { return -1; } } else if (gt_feature_node_number_of_children(parent) > 1) { if (add_to_parent(d, node, parent, err) < 0) { return -1; } } else { if (add_to_current(d, node, parent, err) < 0) { return -1; } } } else { if (gt_feature_node_is_pseudo(parent) && gt_feature_node_is_multi(node)) { if (add_to_rep(d, node, parent, err) < 0) { return -1; } } else { if (add_to_current(d, node, parent, err) < 0) { return -1; } } } } else { /* root nodes always get their own block */ if (add_to_current(d, node, parent, err) < 0) { return -1; } } } /* we can now assume that this node (or its representative) has been processed into the reverse lookup structure */ #ifndef NDEBUG if (gt_feature_node_is_multi(node)) { GtFeatureNode *rep; rep = gt_feature_node_get_multi_representative((GtFeatureNode*) node); gt_assert(gt_hashmap_get(d->nodeinfo, rep)); } else gt_assert(gt_hashmap_get(d->nodeinfo, node)); #endif return 0; }