aboutsummaryrefslogtreecommitdiff
path: root/src/lib/container
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-06-22 16:04:08 +0300
committerrl1987 <rl1987@sdf.lonestar.org>2018-07-21 18:38:33 +0300
commite6c51a056c5be77edeb60d71c1cb36a8680df9af (patch)
treed082a487d9fe2828b550bfbe92e6d06e208071c9 /src/lib/container
parent86549c0d9e636dabe3a0ed9890afe3faf920b7b6 (diff)
downloadtor-e6c51a056c5be77edeb60d71c1cb36a8680df9af.tar.gz
tor-e6c51a056c5be77edeb60d71c1cb36a8680df9af.zip
Make entry_guards_update_primary() shorter
Diffstat (limited to 'src/lib/container')
-rw-r--r--src/lib/container/smartlist.c27
-rw-r--r--src/lib/container/smartlist.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/container/smartlist.c b/src/lib/container/smartlist.c
index dc283e5f50..4b29d834d9 100644
--- a/src/lib/container/smartlist.c
+++ b/src/lib/container/smartlist.c
@@ -189,6 +189,33 @@ smartlist_ints_eq(const smartlist_t *sl1, const smartlist_t *sl2)
return 1;
}
+/**
+ * Return true if there is shallow equality between smartlists -
+ * i.e. all indices correspond to exactly same object (pointer
+ * values are matching). Otherwise, return false.
+ */
+int
+smartlist_ptrs_eq(const smartlist_t *s1, const smartlist_t *s2)
+{
+ if (s1 == s2)
+ return 1;
+
+ // Note: pointers cannot both be NULL at this point, because
+ // above check.
+ if (s1 == NULL || s2 == NULL)
+ return 0;
+
+ if (smartlist_len(s1) != smartlist_len(s2))
+ return 0;
+
+ for (int i = 0; i < smartlist_len(s1); i++) {
+ if (smartlist_get(s1, i) != smartlist_get(s2, i))
+ return 0;
+ }
+
+ return 1;
+}
+
/** Return true iff <b>sl</b> has some element E such that
* tor_memeq(E,<b>element</b>,DIGEST_LEN)
*/
diff --git a/src/lib/container/smartlist.h b/src/lib/container/smartlist.h
index 3b19cbfce4..9705396ac9 100644
--- a/src/lib/container/smartlist.h
+++ b/src/lib/container/smartlist.h
@@ -37,6 +37,9 @@ int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2);
void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2);
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2);
+int smartlist_ptrs_eq(const smartlist_t *s1,
+ const smartlist_t *s2);
+
void smartlist_sort(smartlist_t *sl,
int (*compare)(const void **a, const void **b));
void *smartlist_get_most_frequent_(const smartlist_t *sl,