From: Arnaud Giersch Date: Fri, 20 Dec 2019 22:08:14 +0000 (+0100) Subject: Fix prototype, and use boolean operators. X-Git-Tag: v3.25~248 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/68573f41da7750f37ddef384d5231370a6542998?ds=sidebyside Fix prototype, and use boolean operators. --- diff --git a/include/xbt/automaton.h b/include/xbt/automaton.h index 03339f7073..af1d5e7e52 100644 --- a/include/xbt/automaton.h +++ b/include/xbt/automaton.h @@ -105,7 +105,7 @@ XBT_PUBLIC int xbt_automaton_propositional_symbol_evaluate(xbt_automaton_proposi XBT_PUBLIC xbt_automaton_state_t xbt_automaton_get_current_state(xbt_automaton_t a); XBT_PUBLIC int xbt_automaton_state_compare(xbt_automaton_state_t s1, xbt_automaton_state_t s2); XBT_PUBLIC int xbt_automaton_propositional_symbols_compare_value(xbt_dynar_t s1, xbt_dynar_t s2); -XBT_PUBLIC int xbt_automaton_transition_compare(const void* t1, const void* t2); +XBT_PUBLIC int xbt_automaton_transition_compare(xbt_automaton_transition_t t1, xbt_automaton_transition_t t2); XBT_PUBLIC int xbt_automaton_exp_label_compare(xbt_automaton_exp_label_t l1, xbt_automaton_exp_label_t l2); XBT_PUBLIC void xbt_automaton_state_free_voidp(void* s); XBT_PUBLIC void xbt_automaton_state_free(xbt_automaton_state_t s); diff --git a/src/xbt/automaton/automaton.c b/src/xbt/automaton/automaton.c index e732b9cb54..708b5e1abf 100644 --- a/src/xbt/automaton/automaton.c +++ b/src/xbt/automaton/automaton.c @@ -274,32 +274,14 @@ XBT_PUBLIC const char* xbt_automaton_propositional_symbol_get_name(xbt_automaton } int xbt_automaton_state_compare(xbt_automaton_state_t s1, xbt_automaton_state_t s2){ - /* single id for each state, id and type sufficient for comparison*/ - - if(strcmp(s1->id, s2->id)) - return 1; - - if(s1->type != s2->type) - return 1; - - return 0; - + return (strcmp(s1->id, s2->id) != 0) || (s1->type != s2->type); } -int xbt_automaton_transition_compare(const void *t1, const void *t2){ - - if(xbt_automaton_state_compare(((xbt_automaton_transition_t)t1)->src, ((xbt_automaton_transition_t)t2)->src)) - return 1; - - if(xbt_automaton_state_compare(((xbt_automaton_transition_t)t1)->dst, ((xbt_automaton_transition_t)t2)->dst)) - return 1; - - if(xbt_automaton_exp_label_compare(((xbt_automaton_transition_t)t1)->label,((xbt_automaton_transition_t)t2)->label)) - return 1; - - return 0; - +int xbt_automaton_transition_compare(xbt_automaton_transition_t t1, xbt_automaton_transition_t t2) +{ + return xbt_automaton_state_compare(t1->src, t2->src) || xbt_automaton_state_compare(t1->dst, t2->dst) || + xbt_automaton_exp_label_compare(t1->label, t2->label); } int xbt_automaton_exp_label_compare(xbt_automaton_exp_label_t l1, xbt_automaton_exp_label_t l2){ @@ -311,16 +293,14 @@ int xbt_automaton_exp_label_compare(xbt_automaton_exp_label_t l1, xbt_automaton_ switch(l1->type){ case 0 : // OR case 1 : // AND - if(xbt_automaton_exp_label_compare(l1->u.or_and.left_exp, l2->u.or_and.left_exp)) - res = 1; - else - res = xbt_automaton_exp_label_compare(l1->u.or_and.right_exp, l2->u.or_and.right_exp); + res = xbt_automaton_exp_label_compare(l1->u.or_and.left_exp, l2->u.or_and.left_exp) || + xbt_automaton_exp_label_compare(l1->u.or_and.right_exp, l2->u.or_and.right_exp); break; case 2 : // NOT res = xbt_automaton_exp_label_compare(l1->u.exp_not, l2->u.exp_not); break; case 3 : // predicat - res = strcmp(l1->u.predicat, l2->u.predicat); + res = strcmp(l1->u.predicat, l2->u.predicat) != 0; break; case 4 : // 1 res = 0;