[or-cvs] Add smartlist_reverse and smartlist_pop_last.
Nick Mathewson
nickm at seul.org
Sun Jun 18 07:21:37 UTC 2006
Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv22020/src/common
Modified Files:
container.c container.h
Log Message:
Add smartlist_reverse and smartlist_pop_last.
Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -p -d -r1.58 -r1.59
--- container.c 9 Feb 2006 05:46:48 -0000 1.58
+++ container.c 18 Jun 2006 07:21:35 -0000 1.59
@@ -127,6 +127,32 @@ smartlist_remove(smartlist_t *sl, const
}
}
+/** If <b>sl</b> is nonempty, remove and return the final element. Otherwise,
+ * return NULL. */
+void *
+smartlist_pop_last(smartlist_t *sl)
+{
+ tor_assert(sl);
+ if (sl->num_used)
+ return sl->list[--sl->num_used];
+ else
+ return NULL;
+}
+
+/** Reverse the order of the items in <b>sl</b>. */
+void
+smartlist_reverse(smartlist_t *sl)
+{
+ int i, j;
+ void *tmp;
+ tor_assert(sl);
+ for (i = 0, j = sl->num_used-1; i < j; ++i, --j) {
+ tmp = sl->list[i];
+ sl->list[i] = sl->list[j];
+ sl->list[j] = tmp;
+ }
+}
+
/** If there are any strings in sl equal to element, remove and free them.
* Does not preserve order. */
void
Index: container.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -p -d -r1.29 -r1.30
--- container.h 9 Feb 2006 05:46:48 -0000 1.29
+++ container.h 18 Jun 2006 07:21:35 -0000 1.30
@@ -29,6 +29,8 @@ void smartlist_clear(smartlist_t *sl);
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, const void *element);
+void *smartlist_pop_last(smartlist_t *sl);
+void smartlist_reverse(smartlist_t *sl);
void smartlist_string_remove(smartlist_t *sl, const char *element);
int smartlist_isin(const smartlist_t *sl, const void *element);
int smartlist_string_isin(const smartlist_t *sl, const char *element);
More information about the tor-commits
mailing list