liquid_feedback_core
changeset 369:cad83f274b79
Bugfix: Numerical ordering of suggestion_id in "lf_update_suggestion_order"
author | jbe |
---|---|
date | Sun Mar 17 16:06:16 2013 +0100 (2013-03-17) |
parents | 18289b64def1 |
children | 794974af6d6d |
files | lf_update_suggestion_order.c |
line diff
1.1 --- a/lf_update_suggestion_order.c Sun Mar 17 15:37:25 2013 +0100 1.2 +++ b/lf_update_suggestion_order.c Sun Mar 17 16:06:16 2013 +0100 1.3 @@ -38,8 +38,15 @@ 1.4 int seat; 1.5 }; 1.6 1.7 +static int compare_id(char *id1, char *id2) { 1.8 + int ldiff; 1.9 + ldiff = strlen(id1) - strlen(id2); 1.10 + if (ldiff) return ldiff; 1.11 + else return strcmp(id1, id2); 1.12 +} 1.13 + 1.14 static int compare_candidate(struct candidate *c1, struct candidate *c2) { 1.15 - return strcmp(c1->key, c2->key); 1.16 + return compare_id(c1->key, c2->key); 1.17 } 1.18 1.19 static int candidate_count; 1.20 @@ -248,9 +255,9 @@ 1.21 char *member_id, *suggestion_id; 1.22 member_id = PQgetvalue(res, i, COL_MEMBER_ID); 1.23 suggestion_id = PQgetvalue(res, i, COL_SUGGESTION_ID); 1.24 - if (!candidate_tree || !tfind(suggestion_id, &candidate_tree, (void *)strcmp)) { 1.25 + if (!candidate_tree || !tfind(suggestion_id, &candidate_tree, (void *)compare_id)) { 1.26 candidate_count++; 1.27 - if (!tsearch(suggestion_id, &candidate_tree, (void *)strcmp)) { 1.28 + if (!tsearch(suggestion_id, &candidate_tree, (void *)compare_id)) { 1.29 fprintf(stderr, "Insufficient memory while inserting into candidate tree.\n"); 1.30 abort(); 1.31 } 1.32 @@ -266,7 +273,7 @@ 1.33 } 1.34 candidate_count = 0; 1.35 twalk(candidate_tree, (void *)register_candidate); 1.36 - while (candidate_tree) tdelete(*(void **)candidate_tree, &candidate_tree, (void *)strcmp); 1.37 + while (candidate_tree) tdelete(*(void **)candidate_tree, &candidate_tree, (void *)compare_id); 1.38 printf("Ballot count: %i\n", ballot_count); 1.39 ballots = calloc(ballot_count, sizeof(struct ballot)); 1.40 if (!ballots) {