aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-03-23 00:20:05 -0400
committerNick Mathewson <nickm@torproject.org>2014-03-23 00:20:05 -0400
commit2cfc4453c246bbd964cb9849bc5959bb1c510ae7 (patch)
tree67aa401eef9323e8baff9d01a45490bbd82e939c /src/common
parentf4e2c72beef2821a6f30a31ad487d9d7911df0dc (diff)
parentd769cab3e50979807a526b3ebc5c341c13b12e97 (diff)
downloadtor-2cfc4453c246bbd964cb9849bc5959bb1c510ae7.tar
tor-2cfc4453c246bbd964cb9849bc5959bb1c510ae7.tar.gz
Merge remote-tracking branch 'public/bug9683_rebased'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/container.c20
-rw-r--r--src/common/container.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c
index f489430ca..b937d544f 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -727,6 +727,26 @@ smartlist_uniq_strings(smartlist_t *sl)
smartlist_uniq(sl, compare_string_ptrs_, tor_free_);
}
+/** Helper: compare two pointers. */
+static int
+compare_ptrs_(const void **_a, const void **_b)
+{
+ const void *a = *_a, *b = *_b;
+ if (a<b)
+ return -1;
+ else if (a==b)
+ return 0;
+ else
+ return 1;
+}
+
+/** Sort <b>sl</b> in ascending order of the pointers it contains. */
+void
+smartlist_sort_pointers(smartlist_t *sl)
+{
+ smartlist_sort(sl, compare_ptrs_);
+}
+
/* Heap-based priority queue implementation for O(lg N) insert and remove.
* Recall that the heap property is that, for every index I, h[I] <
* H[LEFT_CHILD[I]] and h[I] < H[RIGHT_CHILD[I]].
diff --git a/src/common/container.h b/src/common/container.h
index 93f0b7114..0d31f2093 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -103,6 +103,7 @@ void smartlist_uniq(smartlist_t *sl,
void smartlist_sort_strings(smartlist_t *sl);
void smartlist_sort_digests(smartlist_t *sl);
void smartlist_sort_digests256(smartlist_t *sl);
+void smartlist_sort_pointers(smartlist_t *sl);
char *smartlist_get_most_frequent_string(smartlist_t *sl);
char *smartlist_get_most_frequent_digest256(smartlist_t *sl);