Esempio n. 1
0
const ExprNode& ExprCopy::index_copy(const Array<const ExprSymbol>& old_x, const Array<const ExprNode>& new_x, const ExprNode& y, int i, int j, bool fold_cst) {

	const ExprVector* vec=dynamic_cast<const ExprVector*>(&y);

	if (vec) {
		const ExprVector* vec2=dynamic_cast<const ExprVector*>(&vec->arg(i));
		if (vec2) {
			return copy(old_x, new_x,  vec2->arg(j));
		} else {
			return index_copy(old_x, new_x, vec->arg(i), j);
		}
	} else {

		const ExprConstant* cst=dynamic_cast<const ExprConstant*>(&y);
		if (cst) {
			assert(cst->dim.is_matrix());
			return ExprConstant::new_scalar(cst->get_matrix_value()[i][j]);
		} else {
			const ExprIndex* tmp=&(y[i][j]);
			const ExprNode& y2=copy(old_x, new_x, *tmp);
			delete &((ExprIndex*) tmp)->expr; // delete y[i][j]
			delete (ExprNode*) tmp;           // delete y[i]
			return y2;
		}
	}
}
Esempio n. 2
0
bst_t bst_copy(bst_t bst) {
    bst_t result = bst_empty();
    if (bst != NULL) {
        result = bst_add(result, index_copy(pair_fst(bst->pair)),
                         data_copy(pair_snd(bst->pair)));
        result->right = bst_copy(bst->right);
        result->left = bst_copy(bst->left);
    }
    return result;
}
Esempio n. 3
0
list_t bst_to_list(bst_t bst, list_t list) {
    if (bst != NULL) {
        index_t index = index_copy(pair_fst(bst->pair));
        data_t data = data_copy(pair_snd(bst->pair));

        if (bst->left != NULL) {
            list = bst_to_list(bst->left, list);
        }
        list = list_append(list, index, data);
        if (bst->right != NULL) {
            list = bst_to_list(bst->right, list);
        }

        index = NULL;
        data = NULL;
    }
    return (list);
}
Esempio n. 4
0
list_t bst_to_list(bst_t bst, list_t list) {

    index_t indexc;
    data_t datac;


    if (bst_type(bst) == isNotEmpty) {

        indexc = index_copy(pair_fst(bst->pair));
        datac = data_copy(pair_snd(bst->pair));

        list = list_append(bst_to_list(bst->izq, list), indexc, datac);

        list = bst_to_list(bst->der, list);

    }

    return (list);

}
Esempio n. 5
0
list_t list_copy(list_t list) {
	
	list_t result = list_empty(),current=list;
	
	index_t index_cop = NULL;
	data_t data_cop = NULL;
	
	while(current!=NULL) {
		index_cop = index_copy(pair_fst(current->elem));
		data_cop = data_copy(pair_snd(current->elem));
		
		result = list_append(result,index_cop,data_cop);
		
		current = current->next;
	}
	current = NULL;
	index_cop = NULL;
	data_cop = NULL;
	
	assert(list_is_equal(list,result));
	
	return result;
}