diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-12 08:27:01 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-12 08:27:01 +0000 |
commit | 2689cb081b4011fea08947e2f7a8f74cd61a1903 (patch) | |
tree | cd8f55e67065dbfee10608f00de525be2f3fe956 /src | |
parent | 63bb27f19d6cb1d27ac557220d8f8b0561d5022f (diff) | |
download | tor-2689cb081b4011fea08947e2f7a8f74cd61a1903.tar.gz tor-2689cb081b4011fea08947e2f7a8f74cd61a1903.zip |
We have so many special cases for smartlists of strings, why not add a sort function?
svn:r5014
Diffstat (limited to 'src')
-rw-r--r-- | src/common/container.c | 12 | ||||
-rw-r--r-- | src/common/container.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c index 766e6deb9c..1e6d1954d2 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -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 { diff --git a/src/common/container.h b/src/common/container.h index 5df4e9e897..56f5e35bf6 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -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)); |