[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] We have so many special cases for smartlists of strings, wh...



Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv18763/src/common

Modified Files:
	container.c container.h 
Log Message:
We have so many special cases for smartlists of strings, why not add a sort function?

Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- container.c	12 Sep 2005 05:20:29 -0000	1.35
+++ container.c	12 Sep 2005 08:27:01 -0000	1.36
@@ -419,6 +419,18 @@
   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 {

Index: container.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- container.h	11 Sep 2005 23:14:14 -0000	1.16
+++ container.h	12 Sep 2005 08:27:01 -0000	1.17
@@ -52,6 +52,7 @@
 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));