# HG changeset patch # User jbe # Date 1363532776 -3600 # Node ID cad83f274b79dcdd88972697fb980e37bc617b01 # Parent 18289b64def1e19bfd8d33e34fc78b89c898b51c Bugfix: Numerical ordering of suggestion_id in "lf_update_suggestion_order" diff -r 18289b64def1 -r cad83f274b79 lf_update_suggestion_order.c --- a/lf_update_suggestion_order.c Sun Mar 17 15:37:25 2013 +0100 +++ b/lf_update_suggestion_order.c Sun Mar 17 16:06:16 2013 +0100 @@ -38,8 +38,15 @@ int seat; }; +static int compare_id(char *id1, char *id2) { + int ldiff; + ldiff = strlen(id1) - strlen(id2); + if (ldiff) return ldiff; + else return strcmp(id1, id2); +} + static int compare_candidate(struct candidate *c1, struct candidate *c2) { - return strcmp(c1->key, c2->key); + return compare_id(c1->key, c2->key); } static int candidate_count; @@ -248,9 +255,9 @@ char *member_id, *suggestion_id; member_id = PQgetvalue(res, i, COL_MEMBER_ID); suggestion_id = PQgetvalue(res, i, COL_SUGGESTION_ID); - if (!candidate_tree || !tfind(suggestion_id, &candidate_tree, (void *)strcmp)) { + if (!candidate_tree || !tfind(suggestion_id, &candidate_tree, (void *)compare_id)) { candidate_count++; - if (!tsearch(suggestion_id, &candidate_tree, (void *)strcmp)) { + if (!tsearch(suggestion_id, &candidate_tree, (void *)compare_id)) { fprintf(stderr, "Insufficient memory while inserting into candidate tree.\n"); abort(); } @@ -266,7 +273,7 @@ } candidate_count = 0; twalk(candidate_tree, (void *)register_candidate); - while (candidate_tree) tdelete(*(void **)candidate_tree, &candidate_tree, (void *)strcmp); + while (candidate_tree) tdelete(*(void **)candidate_tree, &candidate_tree, (void *)compare_id); printf("Ballot count: %i\n", ballot_count); ballots = calloc(ballot_count, sizeof(struct ballot)); if (!ballots) {