X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsn_stage.c;h=158446985371654b3e705644bd6d8e75f470ce6c;hb=785cb745f68b61aa83820a4f85a8c91a0e015228;hp=dc00b448cc2a0c3937eaf5d253eb62a321e863c8;hpb=81effefb7705a491ca062e54f31aa03093c28dbc;p=sort-networks.git diff --git a/src/sn_stage.c b/src/sn_stage.c index dc00b44..1584469 100644 --- a/src/sn_stage.c +++ b/src/sn_stage.c @@ -626,20 +626,47 @@ sn_stage_t *sn_stage_unserialize (char **ret_buffer, size_t *ret_buffer_size) return (s); } /* sn_stage_t *sn_stage_unserialize */ -uint32_t sn_stage_get_hashval (const sn_stage_t *s) /* {{{ */ +int sn_stage_compare (const sn_stage_t *s0, const sn_stage_t *s1) /* {{{ */ { - uint32_t hash; + int status; + int i; + + if (s0 == s1) + return (0); + else if (s0 == NULL) + return (-1); + else if (s1 == NULL) + return (1); + + if (s0->comparators_num < s1->comparators_num) + return (-1); + else if (s0->comparators_num > s1->comparators_num) + return (1); + + for (i = 0; i < s0->comparators_num; i++) + { + status = sn_comparator_compare (s0->comparators + i, s1->comparators + i); + if (status != 0) + return (status); + } + + return (0); +} /* }}} int sn_stage_compare */ + +uint64_t sn_stage_get_hashval (const sn_stage_t *s) /* {{{ */ +{ + uint64_t hash; int i; if (s == NULL) return (0); - hash = (uint32_t) s->depth; + hash = (uint64_t) s->depth; for (i = 0; i < s->comparators_num; i++) hash = (hash * 99991) + sn_comparator_get_hashval (s->comparators + i); return (hash); -} /* }}} uint32_t sn_stage_get_hashval */ +} /* }}} uint64_t sn_stage_get_hashval */ /* vim: set shiftwidth=2 softtabstop=2 expandtab fdm=marker : */