qsort compare functions

David Relson relson at osagesoftware.com
Fri Nov 22 06:17:11 CET 2002


Greetings,

After today's fix, the compare routines called by qsort both look like the 
following code:

     const discrim_t *d1 = id1;
     const discrim_t *d2 = id2;

     double d = d2->prob - d1->prob;
     if (fabs(d) < EPS) return strcmp(d1->key, d2->key);
     if (d1->prob > d2->prob) return 1;
     if (d1->prob < d2->prob) return -1;
     return 0;

Qsort simply wants to know how to order two items.  Bogofilter wants them 
in probability order (primarily) and  alphabetic order 
(secondarily).  Given this info, I assert that the proper code is:

     const discrim_t *d1 = id1;
     const discrim_t *d2 = id2;

     if (d1->prob > d2->prob) return 1;
     if (d1->prob < d2->prob) return -1;
     return strcmp(d1->key, d2->key);

If there are no objections, I shall make this correction.

David





More information about the bogofilter-dev mailing list