[or-cvs] Add useful smartlist_string_remove function.

Nick Mathewson nickm at seul.org
Sun Apr 3 05:52:34 UTC 2005


Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv30313/src/common

Modified Files:
	container.c container.h 
Log Message:
Add useful smartlist_string_remove function.

Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- container.c	1 Apr 2005 20:15:54 -0000	1.22
+++ container.c	3 Apr 2005 05:52:32 -0000	1.23
@@ -118,6 +118,21 @@
     }
 }
 
+/** If there are any string in sl equal to element, remove the first.
+ * Does not preserve order. */
+void
+smartlist_string_remove(smartlist_t *sl, const char *element)
+{
+  int i;
+  size_t len = smartlist_len(sl);
+  for (i = 0; i < len; ++i) {
+    if (!strcmp(element, smartlist_get(sl, i))) {
+      smartlist_del(sl, i);
+      return;
+    }
+  }
+}
+
 /** Return true iff some element E of sl has E==element.
  */
 int smartlist_isin(const smartlist_t *sl, void *element) {

Index: container.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- container.h	1 Apr 2005 20:15:54 -0000	1.11
+++ container.h	3 Apr 2005 05:52:32 -0000	1.12
@@ -30,6 +30,7 @@
 void smartlist_add(smartlist_t *sl, void *element);
 void smartlist_add_all(smartlist_t *sl, const smartlist_t *s2);
 void smartlist_remove(smartlist_t *sl, void *element);
+void smartlist_string_remove(smartlist_t *sl, const char *element);
 int smartlist_isin(const smartlist_t *sl, void *element);
 int smartlist_string_isin(const smartlist_t *sl, const char *element);
 int smartlist_string_num_isin(const smartlist_t *sl, int num);



More information about the tor-commits mailing list