int max_heapify(int *A, int i, int heapSize){ int l = left_index(i); int r = right_index(i); int largest; if((l < heapSize) && (A[l] > A[i])){ largest = l; } else{ largest = i; } if((r < heapSize) && (A[r] > A[largest])){ largest = r; } if(largest != i){ int temp = 0; temp = A[i]; A[i] = A[largest]; A[largest] = temp; max_heapify(A, largest, heapSize); } }
void bridge_document_rep::my_exec_until (path p) { if (is_nil (acc)) { int i; for (i=0; i<p->item; i++) brs[i]->exec_until (path (right_index (brs[i]->st)), true); if (i<N(st)) brs[i]->exec_until (p->next); } else acc->my_exec_until (p); }
tree selection_compute (tree t, path start, path end) { int i1= start->item; int i2= end->item; path p1= start->next; path p2= end->next; if (is_nil (p1) || is_nil (p2)) { if (start == path (right_index (t))) return ""; if (end == path (0)) return ""; if (start == end) return ""; if (is_nil (p1) && is_nil (p2)) { if (is_compound (t)) return copy (t); if (i1>=i2) return ""; return t->label (i1, i2); } if (is_compound (t) && (!is_format (t))) return copy (t); if (is_nil (p1)) { i1= 0; p1= (start->item==0? 0: right_index (t[i1])); } if (is_nil (p2)) { i2= N(t)-1; p2= (end->item==0? 0: right_index (t[i2])); } } if (i1==i2) return selection_compute (t[i1], p1, p2); if (is_compound (t) && (!is_format (t))) return copy (t); int i; tree r (t, i2-i1+1); r[0] = selection_compute (t[i1], p1, path (right_index (t[i1]))); r[N(r)-1]= selection_compute (t[i2], path (0), p2); for (i=1; i<N(r)-1; i++) r[i]= copy (t[i+i1]); return r; }
void bridge_docrange_rep::my_exec_until (path p) { if (p->item < begin); else if ((p->item >= end) && ((status & VALID_MASK) == PROCESSED)) env->patch_env (changes); else if (divide) { int i, n= N(acc); for (i=0; i<n; i++) acc[i]->my_exec_until (p); } else { int i; for (i=begin; i<p->item; i++) brs[i]->exec_until (path (right_index (brs[i]->st)), true); if (p->item < end) brs[i]->exec_until (p->next); } }
void edit_select_rep::select_enlarge () { path sp, sq; if (start_p == end_p) { sp= path_up (start_p); sq= sp; } else { sp= common (start_p, end_p); if (!(rp < sp)) { selection_cancel (); set_message ("", ""); return; } sq= path_up (sp); } path pp= sp, p1= start_p, p2= end_p; if (start_p == pp * 0 && end_p == pp * right_index (subtree (et, pp))) if (!is_nil (pp)) pp= path_up (pp); if (is_func (subtree (et, pp), TFORMAT)) pp= path_up (pp); if (semantic_select (pp, p1, p2, 1)) select (p1, p2); else { if (is_atomic (subtree (et, sp))) select_enlarge_text (); else select (sq * 0, sq * 1); } path p = common (start_p, end_p); tree st= subtree (et, p); if (drd->var_without_border (L(st)) || is_func (st, TFORMAT) || is_func (st, DOCUMENT, 1) || is_script (st) || incomplete_script_selection (st, start_p / p, end_p / p)) select_enlarge (); else { tree s; if (is_atomic (st)) s= "text"; else if (is_func (st, COMPOUND)) s= as_string (st[0]); else if (is_func (st, WITH)) s= concat ("with ", as_string (st[0])); else s= as_string (L(st)); set_message (concat ("selected ", s), "enlarge selection"); } selecting= shift_selecting= false; }