]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add smartlist_reverse and smartlist_pop_last.
authorNick Mathewson <nickm@torproject.org>
Sun, 18 Jun 2006 07:21:35 +0000 (07:21 +0000)
committerNick Mathewson <nickm@torproject.org>
Sun, 18 Jun 2006 07:21:35 +0000 (07:21 +0000)
svn:r6634

src/common/container.c
src/common/container.h

index 33a77cd42c51a27d3b3972e3f63a35451a6b3e24..06e810a1494e7f99cfded8cf8ae0c01747614b27 100644 (file)
@@ -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
index 83c0f28229fbd953d1f7220b0e1f1616f5de7ddf..40cf13f4fa1ed858d2ec99ab5e068636d40b208f 100644 (file)
@@ -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);