From 7a5ac618c0340d3281a0db49f0cd770edf1dccc1 Mon Sep 17 00:00:00 2001 From: Cedric Bastoul Date: Mon, 19 Dec 2011 14:04:20 +0100 Subject: [PATCH] Add osl_relation_add function --- include/osl/relation.h | 3 +- source/relation.c | 75 +++++++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/include/osl/relation.h b/include/osl/relation.h index f6f9db2..d569897 100644 --- a/include/osl/relation.h +++ b/include/osl/relation.h @@ -153,6 +153,8 @@ void osl_relation_free(osl_relation_p); *****************************************************************************/ osl_relation_p osl_relation_nclone(osl_relation_p, int); osl_relation_p osl_relation_clone(osl_relation_p); +void osl_relation_add(osl_relation_p *, osl_relation_p); +osl_relation_p osl_relation_union(osl_relation_p, osl_relation_p); void osl_relation_replace_vector(osl_relation_p, osl_vector_p, int); void osl_relation_insert_vector(osl_relation_p, osl_vector_p, int); osl_relation_p osl_relation_concat_vector(osl_relation_p, osl_vector_p); @@ -169,7 +171,6 @@ void osl_relation_insert_columns(osl_relation_p, osl_relation_p,int); osl_relation_p osl_relation_concat_constraints(osl_relation_p, osl_relation_p); int osl_relation_equal(osl_relation_p, osl_relation_p); int osl_relation_integrity_check(osl_relation_p, int, int, int,int); -osl_relation_p osl_relation_union(osl_relation_p, osl_relation_p); void osl_relation_set_attributes(osl_relation_p, int, int, int, int); void osl_relation_set_type(osl_relation_p, int); int osl_relation_get_array_id(osl_relation_p); diff --git a/source/relation.c b/source/relation.c index 9d00403..db942c9 100644 --- a/source/relation.c +++ b/source/relation.c @@ -1253,6 +1253,47 @@ osl_relation_p osl_relation_clone(osl_relation_p relation) { /** + * osl_relation_add function: + * this function adds a relation (union) at the end of the relation (union) + * pointed by r1. No new relation is created: this functions links the two + * input unions. If the first relation is NULL, it is set to the + * second relation. + * \param[in,out] r1 Pointer to the first relation (union). + * \param[in] r2 The second relation (union). + */ +void osl_relation_add(osl_relation_p *r1, osl_relation_p r2) { + while (*r1 != NULL) + r1 = &((*r1)->next); + + *r1 = r2; +} + + +/** + * osl_relation_union function: + * this function builds a new relation from two relations provided + * as parameters. The new relation is built as an union of the + * two relations: the list of constraint sets are linked together. + * \param[in] r1 The first relation. + * \param[in] r2 The second relation. + * \return A new relation corresponding to the union of r1 and r2. + */ +osl_relation_p osl_relation_union(osl_relation_p r1, + osl_relation_p r2) { + osl_relation_p copy1, copy2; + + if ((r1 == NULL) && (r2 == NULL)) + return NULL; + + copy1 = osl_relation_clone(r1); + copy2 = osl_relation_clone(r2); + osl_relation_add(©1, copy2); + + return copy1; +} + + +/** * osl_relation_replace_vector function: * this function replaces the "row"^th row of a relation "relation" with the * vector "vector". It directly updates the relation union part pointed @@ -1873,40 +1914,6 @@ int osl_relation_integrity_check(osl_relation_p relation, /** - * osl_relation_union function: - * this function builds a new relation from two relations provided - * as parameters. The new relation is built as an union of the - * two relations: the list of constraint sets are linked together. - * \param[in] r1 The first relation. - * \param[in] r2 The second relation. - * \return A new relation corresponding to the union of r1 and r2. - */ -osl_relation_p osl_relation_union(osl_relation_p r1, - osl_relation_p r2) { - osl_relation_p copy1, copy2, tmp; - - if ((r1 == NULL) && (r2 == NULL)) - return NULL; - - copy1 = osl_relation_clone(r1); - copy2 = osl_relation_clone(r2); - - if ((r1 != NULL) && (r2 == NULL)) - return copy1; - - if ((r1 == NULL) && (r2 != NULL)) - return copy2; - - tmp = copy1; - while (tmp->next != NULL) - tmp = tmp->next; - - tmp->next = copy2; - return copy1; -} - - -/** * osl_relation_set_attributes function: * this functions sets the attributes of a relation provided as a * parameter. It updates the relation directly. -- 2.11.4.GIT