We have so many special cases for smartlists of strings, why not add a sort function?

svn:r5014
This commit is contained in:
Nick Mathewson 2005-09-12 08:27:01 +00:00
parent 63bb27f19d
commit 2689cb081b
2 changed files with 13 additions and 0 deletions

View File

@ -419,6 +419,18 @@ smartlist_bsearch(smartlist_t *sl, const void *key,
return r ? *r : NULL;
}
static int
_compare_string_ptrs(void **_a, void **_b)
{
return strcmp((char*)*_a, (char*)*_b);
}
void
smartlist_sort_strings(smartlist_t *sl)
{
smartlist_sort(sl, _compare_string_ptrs);
}
/* Splay-tree implementation of string-to-void* map
*/
typedef struct strmap_entry_t {

View File

@ -52,6 +52,7 @@ void smartlist_del_keeporder(smartlist_t *sl, int idx);
void smartlist_insert(smartlist_t *sl, int idx, void *val);
void smartlist_sort(smartlist_t *sl,
int (*compare)(const void **a, const void **b));
void smartlist_sort_strings(smartlist_t *sl);
void *smartlist_bsearch(smartlist_t *sl, const void *key,
int (*compare)(const void *key, const void **member));