model_server/smt/src/smt_cut.cxx
// Unites all objects under parent of the first one
// If do_regions is 1, creates SMT_temp subtree for each region that
// contains more than one node
Unites all objects under parent of the first one
If do_regions is 1, creates SMT_temp subtree for each region that
contains more than one node
Unites all objects under parent of the first one If do_regions is 1 creates SMT_temp subtree for each region that contains more than one node
smtTree * smt_unite(Obj *ob, objArr_Int &region, int do_regions)
{
    Initialize(smt_unite);
    smtTree* st=0, *en=0, *root = NULL, *el = NULL, *tmp = NULL;
    Obj *obj_el;
    int len = 0, node_ind = 0;
    int cur_len;
    int no_regs = (&region) ? (region.size() / 4) : 0;
    int reg_st = -1, reg_en = -1, reg_ind = -1;
    if (&region && do_regions && no_regs) {
	reg_ind++;
	reg_st = region[reg_ind];
	reg_en = region[reg_ind + 2];
    }
    ForEach(obj_el, *ob){
	el = checked_cast(smtTree,obj_el);
	if (st) 
	{
	    if(  el->get_parent() )
		continue;
	    en->put_after(el);
	}
	else
	    st = el;
	en =  el;
	cur_len = en->start () + en->length ();
	if ( cur_len > len )
	    len = cur_len;
	if (do_regions && reg_st > -1 && reg_en > -1 && reg_ind > -1) {
	    if (reg_en > reg_st && reg_st == node_ind) {
		tmp = new smtTree;
		tmp->type = tmp->extype = SMT_temp;
		en->put_after (tmp);
		tmp->put_first (en);
	    }
	    if ( reg_en == node_ind ) {
		if ( reg_en > reg_st && tmp ) {
		    en = tmp;
		    tmp = NULL;
		}
		reg_ind ++;
		if (reg_ind < no_regs) {
		    reg_st = region[reg_ind*4];
		    reg_en = region[reg_ind*4 + 2];
		} else
		    reg_ind = reg_st = reg_en = -1;
	    }
	}
	node_ind++;
    }
    smtHeader *h = (st) ? checked_cast(smtHeader,st->get_header()) : NULL;
    if ( !h )
	return NULL;
    char * nb = (char *)psetmalloc(len);
    h->src_asize = h->src_size = len;
    strncpy(nb, h->srcbuf, len);
    h->srcbuf = nb;
    h->tidy_tree();
    if ( st != en ) {
	h->parsed = 1;
	root = st->get_parent();
    } else {
	root = st;
    }
    objArr& nodes = *(objArr*)ob;
    int off1, off2;
    smtTreePtr node1, node2;
    if (&region) {
	int no_reg = region.size();
	for (reg_ind = 0 ; reg_ind < no_reg ; reg_ind += 4) {
	    node1 = checked_cast(smtTree,nodes[region[reg_ind]]);
	    off1 = region[reg_ind+1];
	    node2 = checked_cast(smtTree,nodes[region[reg_ind+2]]);
	    off2 = region[reg_ind+3];
	    node1 = node1->get_first_leaf();
	    node2 = node2->get_last_leaf();
	    smt_cut_tail(node2, off2);
	    smt_cut_head(node1, off1);
	}
    }
    return root;
}
smtTree * smt_unite ( Obj * ob , objArr_Int & region , int do_regions ) { Initialize ( smt_unite ) ; smtTree * st = 0 , * en = 0 , * root = NULL , * el = NULL , * tmp = NULL ; Obj * obj_el ; int len = 0 , node_ind = 0 ; int cur_len ; int no_regs = ( & region ) ? ( region . size ( ) / 4 ) : 0 ; int reg_st = -1 , reg_en = -1 , reg_ind = -1 ; if ( & region && do_regions && no_regs ) { reg_ind ++ ; reg_st = region [ reg_ind ] ; reg_en = region [ reg_ind + 2 ] ; } ForEach ( obj_el , * ob ) { el = checked_cast ( smtTree , obj_el ) ; if ( st ) { if ( el -> get_parent ( ) ) continue ; en -> put_after ( el ) ; } else st = el ; en = el ; cur_len = en -> start ( ) + en -> length ( ) ; if ( cur_len > len ) len = cur_len ; if ( do_regions && reg_st > -1 && reg_en > -1 && reg_ind > -1 ) { if ( reg_en > reg_st && reg_st == node_ind ) { tmp = new smtTree ; tmp -> type = tmp -> extype = SMT_temp ; en -> put_after ( tmp ) ; tmp -> put_first ( en ) ; } if ( reg_en == node_ind ) { if ( reg_en > reg_st && tmp ) { en = tmp ; tmp = NULL ; } reg_ind ++ ; if ( reg_ind < no_regs ) { reg_st = region [ reg_ind * 4 ] ; reg_en = region [ reg_ind * 4 + 2 ] ; } else reg_ind = reg_st = reg_en = -1 ; } } node_ind ++ ; } smtHeader * h = ( st ) ? checked_cast ( smtHeader , st -> get_header ( ) ) : NULL ; if ( ! h ) return NULL ; char * nb = ( char * ) psetmalloc ( len ) ; h -> src_asize = h -> src_size = len ; strncpy ( nb , h -> srcbuf , len ) ; h -> srcbuf = nb ; h -> tidy_tree ( ) ; if ( st != en ) { h -> parsed = 1 ; root = st -> get_parent ( ) ; } else { root = st ; } objArr & nodes = * ( objArr * ) ob ; int off1 , off2 ; smtTreePtr node1 , node2 ; if ( & region ) { int no_reg = region . size ( ) ; for ( reg_ind = 0 ; reg_ind < no_reg ; reg_ind += 4 ) { node1 = checked_cast ( smtTree , nodes [ region [ reg_ind ] ] ) ; off1 = region [ reg_ind + 1 ] ; node2 = checked_cast ( smtTree , nodes [ region [ reg_ind + 2 ] ] ) ; off2 = region [ reg_ind + 3 ] ; node1 = node1 -> get_first_leaf ( ) ; node2 = node2 -> get_last_leaf ( ) ; smt_cut_tail ( node2 , off2 ) ; smt_cut_head ( node1 , off1 ) ; } } return root ; }
Unites all objects under parent of the first one
If do_regions is 1, creates SMT_temp subtree for each region that
contains more than one node
Unites all objects under parent of the first one If do_regions is 1 creates SMT_temp subtree for each region that contains more than one node
// Only unite upper most nodes of subtrees cut from other // smt`s. // copy srcbuf