summaryrefslogtreecommitdiff
path: root/src/common/container.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-06-18 07:21:35 +0000
committerNick Mathewson <nickm@torproject.org>2006-06-18 07:21:35 +0000
commit78428dccdbd47af0ca8d39b40c8a3e512d1c1036 (patch)
treec12ae117ccc9984d08efe98e2df4bfa59691b9b3 /src/common/container.c
parent7a3ac5ee0d9c08529404068dd47011ca1ef0bc08 (diff)
downloadtor-78428dccdbd47af0ca8d39b40c8a3e512d1c1036.tar.gz
tor-78428dccdbd47af0ca8d39b40c8a3e512d1c1036.zip
Add smartlist_reverse and smartlist_pop_last.
svn:r6634
Diffstat (limited to 'src/common/container.c')
-rw-r--r--src/common/container.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c
index 33a77cd42c..06e810a149 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -127,6 +127,32 @@ smartlist_remove(smartlist_t *sl, const void *element)
}
}
+/** 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