/* * this routine takes two proposals and conjoins them (or) */ struct db_sa *sa_merge_proposals(struct db_sa *a, struct db_sa *b) { struct db_sa *n; unsigned int i, j, k; if (a == NULL || a->prop_conj_cnt == 0) return sa_copy_sa(b, 0); if (b == NULL || b->prop_conj_cnt == 0) return sa_copy_sa(a, 0); n = clone_thing(*a, "conjoin sa"); passert(a->prop_conj_cnt == b->prop_conj_cnt); passert(a->prop_conj_cnt == 1); n->prop_conjs = clone_bytes(n->prop_conjs, n->prop_conj_cnt * sizeof(n->prop_conjs[0]), "sa copy prop conj array"); for (i = 0; i < n->prop_conj_cnt; i++) { struct db_prop_conj *pca = &n->prop_conjs[i]; struct db_prop_conj *pcb = &b->prop_conjs[i]; passert(pca->prop_cnt == pcb->prop_cnt); passert(pca->prop_cnt == 1); pca->props = clone_bytes(pca->props, pca->prop_cnt * sizeof(pca->props[0]), "sa copy prop array"); for (j = 0; j < pca->prop_cnt; j++) { struct db_prop *pa = &pca->props[j]; struct db_prop *pb = &pcb->props[j]; struct db_trans *t; int t_cnt = (pa->trans_cnt + pb->trans_cnt); t = alloc_bytes(t_cnt * sizeof(pa->trans[0]), "sa copy trans array"); memcpy(t, pa->trans, (pa->trans_cnt) * sizeof(pa->trans[0])); memcpy(t + (pa->trans_cnt), pb->trans, (pb->trans_cnt) * sizeof(pa->trans[0])); pa->trans = t; pa->trans_cnt = t_cnt; for (k = 0; k < pa->trans_cnt; k++) clone_trans(&pa->trans[k], 0); } } n->parentSA = a->parentSA; return n; }
void clone_prop(struct db_prop *p, int extra) { unsigned int i; p->trans = clone_bytes(p->trans , (p->trans_cnt+extra)*sizeof(p->trans[0]) , "sa copy trans array"); for(i=0; i<p->trans_cnt; i++) { clone_trans(&p->trans[i]); } }
static void clone_prop(struct db_prop *p, int extra) { unsigned int i; p->trans = clone_bytes(p->trans, (p->trans_cnt + extra) * sizeof(p->trans[0]), "sa copy trans array"); /* p->trans_cnt is unchanged */ for (i = 0; i < p->trans_cnt; i++) clone_trans(&p->trans[i], 0); }
/* * clone the sa, but keep only the first transform (if any) of the first proposal (if any) * ??? does this make sense? */ struct db_sa *sa_copy_sa_first(struct db_sa *sa) { struct db_sa *nsa; struct db_prop_conj *pc; struct db_prop *p; nsa = clone_thing(*sa, "sa copy prop_conj"); nsa->dynamic = TRUE; if (nsa->prop_conj_cnt == 0) return nsa; nsa->prop_conj_cnt = 1; nsa->prop_conjs = clone_bytes(nsa->prop_conjs, sizeof(nsa->prop_conjs[0]), "sa copy 1 prop conj array"); pc = &nsa->prop_conjs[0]; if (pc->prop_cnt == 0) return nsa; pc->prop_cnt = 1; pc->props = clone_bytes(pc->props, sizeof(pc->props[0]), "sa copy 1 prop array"); p = &pc->props[0]; if (p->trans_cnt == 0) return nsa; p->trans_cnt = 1; p->trans = clone_bytes(p->trans, sizeof(p->trans[0]), "sa copy 1 trans array"); clone_trans(&p->trans[0], 0); return nsa; }