oid_t dbRtreePage::insert(dbDatabase* db, rectangle const& r, oid_t pageId, oid_t recordId, int level) { dbRtreePage* pg = (dbRtreePage*)db->put(pageId); int n = pg->n; branch br; if (--level != 0) { // not leaf page int i, mini = 0; area_t min_incr = INFINITY; area_t best_area = INFINITY; for (i = 0; i < n; i++) { area_t r_area = area(pg->b[i].rect); area_t incr = area(pg->b[i].rect + r) - r_area; if (incr < min_incr) { best_area = r_area; min_incr = incr; mini = i; } else if (incr == min_incr && r_area < best_area) { best_area = r_area; mini = i; } } oid_t q = insert(db, r, pg->b[mini].p, recordId, level); pg = (dbRtreePage*)db->get(pageId); if (q == 0) { // child was not split pg->b[mini].rect += r; return 0; } else { // child was split cover(db, pg->b[mini].p, pg->b[mini].rect); br.p = q; cover(db, q, br.rect); return add_branch(db, pageId, br); } } else { br.p = recordId; br.rect = r; return add_branch(db, pageId, br); } }
/** * Options without any -X prefix, so these options define our branch paths. * example arg string: "branch1=RW:branch2=RO:branch3=RO" */ static int parse_branches(const char *arg) { // the last argument is our mountpoint, don't take it as branch! if (uopt.nbranches) return 0; // We don't free the buf as parts of it may go to branches char *buf = strdup(arg); char **ptr = (char **)&buf; char *branch; while ((branch = strsep(ptr, ROOT_SEP)) != NULL) { if (strlen(branch) == 0) continue; add_branch(branch); } free(buf); return uopt.nbranches; }
void Composite::add_first_reconstruction(Reconstruction * reconstruction){ // Traverse reconstruction: copy branches and create decision points NeuronSegment *segment, *composite_segment; BranchContainer * branch, *branch_parent; CompositeBranchContainer *composite_parent; std::set<pair<CompositeBranchContainer *, CompositeBranchContainer *> > connection_pair; Connection * connection; DecisionPoint * decision_point; std::stack<pair<NeuronSegment *, BranchContainer *> > segment_stack; // Push root of reconstruction, and null pointer as there is no parent segment_stack.push(pair<NeuronSegment *, BranchContainer *>(reconstruction->get_tree(),nullptr)); pair<NeuronSegment *, BranchContainer *> segment_pair; // Process each branch (create CompositeBranchContainers and DecisionPoints), handling via a stack int count = 0; while (!segment_stack.empty()){ count++; segment_pair = segment_stack.top(); segment_stack.pop(); segment = segment_pair.first; // Get parent of current reconstruction branch branch_parent = segment_pair.second; // Create branch container for this segment //branch = new BranchContainer(reconstruction,segment,branch_parent); branch = reconstruction->get_branch_by_segment(segment); // Copy segment and create composite branch out of it composite_segment = copy_segment_markers(segment); CompositeBranchContainer * composite_branch = new CompositeBranchContainer(composite_segment); add_branch(composite_branch); // Create links between branch and composite branch composite_branch->add_branch_match(branch); branch->set_composite_match(composite_branch); // Create a Decision Point if the branch has a parent if (!branch_parent){ // If this is the root, create new composite reconstruction pointing to the root composite segment c_root = composite_branch; c_root_segment = composite_branch->get_segment(); }else{ // Get composite parent of new composite branch composite_parent = branch_parent->get_composite_match(); composite_branch->set_parent(composite_parent); // Create decision point (which creates the connection) if (composite_parent->get_decision_point2()){ composite_branch->set_decision_point1(composite_parent->get_decision_point2()); }else{ decision_point = new DecisionPoint(); decision_point->add_connection(composite_branch, composite_parent, reconstruction, reconstruction->get_confidence()); composite_branch->set_decision_point1(decision_point); composite_parent->set_decision_point2(decision_point); } } // Add children of the current segment along with the newly created composite segment for connecting for (NeuronSegment *child : segment->child_list){ segment_stack.push(pair<NeuronSegment *,BranchContainer *>(child, branch)); } } printf("Processed %d segments in creating first composite\n",count); };
int main(int ac, const char **av) { char mbpwd[MAXPATHLEN]; wchar_t pwd[MAXPATHLEN]; size_t len; char *t; int found_repo = 0; if (ac != 1) { printf("usage: prwd\n"); exit(-1); } setlocale(LC_ALL, ""); /* Populate $HOME */ t = getenv("HOME"); mbstowcs(home, t, MAXPATHLEN); if (home == NULL || *home == '\0') errx(0, "Unknown variable '$HOME'."); /* Get the working directory */ t = getcwd(NULL, MAXPATHLEN); if (t == NULL) errx(0, "Unable to get current working directory."); mbstowcs(pwd, t, MAXPATHLEN); free(t); read_config(); /* Replace the beginning with ~ for directories within $HOME. */ add_alias(L"~", home, 0); /* Alias handling */ replace_aliases(pwd); /* Newsgroup mode, keep only the first letters. */ if (cfg_newsgroup == 1) newsgroupize(pwd); /* If the path is still too long, crop it. */ len = wcslen(pwd); if (cfg_maxpwdlen > 0 && len > cfg_maxpwdlen) { if (cfg_cleancut == 1 && cfg_newsgroup != 1) { cleancut(pwd); } else { quickcut(pwd, len); } } /* If mercurial is enabled, show the branch */ if (cfg_mercurial == 1) { found_repo = add_branch(pwd, VCS_MERCURIAL); } if (found_repo == 0 && cfg_git == 1) { add_branch(pwd, VCS_GIT); } wcstombs(mbpwd, pwd, MAXPATHLEN); puts(mbpwd); return 0; }
/* * Main prwd functionality, prints a reduced working directory. */ void prwd(void) { size_t len; int found_repo = 0; char *wd = NULL; char *wd_env = NULL; char mbs_wd[MAX_OUTPUT_LEN]; wchar_t wcs_wd[MAX_OUTPUT_LEN]; struct stat sa, sb; wd = getcwd(NULL, MAXPATHLEN); if (wd == NULL) errx(100, "unable to get current working directory"); if (stat(wd, &sa) == -1) err(100, "stat(wd_real)"); /* * If we can get a valid PWD from the environment, that turns out to be * the same directory, then we should use it, it provides more context * if the shell is located in a symlink. */ wd_env = getenv("PWD"); if (wd_env != NULL && stat(wd_env, &sb) == 0) { if (sa.st_ino == sb.st_ino && sa.st_dev == sb.st_dev) { free(wd); wd = wd_env; } } mbstowcs(wcs_wd, wd, MAX_OUTPUT_LEN); /* Replace the beginning with ~ for directories within $HOME. */ add_alias(L"~", home, 0); /* Alias handling */ replace_aliases(wcs_wd); /* Newsgroup mode, keep only the first letters. */ if (cfg_newsgroup == 1) newsgroupize(wcs_wd); /* If the path is still too long, crop it. */ len = wcslen(wcs_wd); if (cfg_maxpwdlen > 0 && len > cfg_maxpwdlen) { if (cfg_cleancut == 1 && cfg_newsgroup != 1) { cleancut(wcs_wd); } else { quickcut(wcs_wd, len); } } /* If mercurial or git is enabled, show the branch */ if (cfg_mercurial == 1) { found_repo = add_branch(wcs_wd, VCS_MERCURIAL); } if (found_repo == 0 && cfg_git == 1) { add_branch(wcs_wd, VCS_GIT); } /* Do we show the hostname? */ if (cfg_hostname == 1) { add_hostname(wcs_wd); } /* Add the '$' or '#' character depending if your root. */ if (cfg_uid_indicator == 1) { add_uid_indicator(wcs_wd); } wcstombs(mbs_wd, wcs_wd, MAX_OUTPUT_LEN); puts(mbs_wd); }