diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-07-30 08:49:49 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-07-30 08:49:49 -0400 |
commit | 13393b2d913545aec54d17fb3402906ab4e04ad7 (patch) | |
tree | e5c8ef84ff6fa4f4f34539566bb41f4d534e55a4 /src/lib | |
parent | b8e94b2f1d0df8152fd7b9726a470aa83970b3c5 (diff) | |
parent | e9f6f742b2729ee62e97711f08fec8e8a97393d7 (diff) | |
download | tor-13393b2d913545aec54d17fb3402906ab4e04ad7.tar.gz tor-13393b2d913545aec54d17fb3402906ab4e04ad7.zip |
Merge remote-tracking branch 'rl1987/ticket21349_4'
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/container/smartlist.c | 27 | ||||
-rw-r--r-- | src/lib/container/smartlist.h | 3 |
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, |