[cvs] SF.net SVN: bogofilter:[6793] trunk/bogofilter/src
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2009-02-14 18:27:48
|
Revision: 6793 http://bogofilter.svn.sourceforge.net/bogofilter/?rev=6793&view=rev Author: relson Date: 2009-02-14 18:27:45 +0000 (Sat, 14 Feb 2009) Log Message: ----------- Replace qsort with listsort. Modified Paths: -------------- trunk/bogofilter/src/wordhash.c trunk/bogofilter/src/wordhash.h Modified: trunk/bogofilter/src/wordhash.c =================================================================== --- trunk/bogofilter/src/wordhash.c 2009-02-14 18:21:48 UTC (rev 6792) +++ trunk/bogofilter/src/wordhash.c 2009-02-14 18:27:45 UTC (rev 6793) @@ -29,6 +29,7 @@ #include <string.h> #include <stddef.h> /* for offsetof */ +#include "listsort.h" #include "wordhash.h" #include "xmalloc.h" @@ -440,12 +441,13 @@ return val; } -static int compare_hashnode_t(const void *const ihn1, const void *const ihn2) +/* compare_hashnode_t - sort by ascending token text */ + +static int compare_hashnode_t(const void *const pv1, const void *const pv2) { - const hashnode_t *hn1 = *(const hashnode_t *const *)ihn1; - const hashnode_t *hn2 = *(const hashnode_t *const *)ihn2; - int cmp = word_cmp(hn1->key, hn2->key); - return cmp; + const hashnode_t *hn1 = (const hashnode_t *)pv1; + const hashnode_t *hn2 = (const hashnode_t *)pv2; + return word_cmp(hn1->key, hn2->key); } static wordcnts_t *wordhash_get_counts(wordhash_t *wh, hashnode_t *n) @@ -473,26 +475,13 @@ } } +/* wordhash_sort - sort by ascending token text */ + void wordhash_sort (wordhash_t *wh) { - hashnode_t *node; + wh->iter_head = listsort(wh->iter_head, &compare_hashnode_t, false, false); - if (wh->size == 0 - || wh->type != WH_NORMAL - || msg_count_file) - return; - - wh->order = (hashnode_t **) xcalloc(wh->size, sizeof(hashnode_t *)); - - wh->count = 0; - for (node = wordhash_first(wh); node != NULL; node = wordhash_next(wh)) - wh->order[wh->count++] = node; - - qsort(wh->order, wh->count, sizeof(hashnode_t *), compare_hashnode_t); - - wh->type = WH_ORDERED; - return; } Modified: trunk/bogofilter/src/wordhash.h =================================================================== --- trunk/bogofilter/src/wordhash.h 2009-02-14 18:21:48 UTC (rev 6792) +++ trunk/bogofilter/src/wordhash.h 2009-02-14 18:27:45 UTC (rev 6793) @@ -7,10 +7,10 @@ /* Hash entry. */ typedef struct hashnode_t { + /*@dependent@*/ struct hashnode_t *iter_next; /* Next item added to hash. For fast traversal */ + struct hashnode_t *next; /* Next item in linked list of items with same hash */ word_t *key; /* word key */ void *buf; /* Associated buffer. To be used by caller. */ - struct hashnode_t *next; /* Next item in linked list of items with same hash */ - /*@dependent@*/ struct hashnode_t *iter_next; /* Next item added to hash. For fast traversal */ } hashnode_t; typedef struct wh_alloc_node { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |