[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/release-0.2.2] New smartlist function to see if two lists of strings are equal.



commit 2253697a04c926edb1a5f18727a6cd24528730b1
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri May 13 16:18:53 2011 -0400

    New smartlist function to see if two lists of strings are equal.
    
    We'll use this to detect changes in CSV options.
---
 src/common/container.c |   19 +++++++++++++++++++
 src/common/container.h |    2 ++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/common/container.c b/src/common/container.c
index 09d4bb1..ca49cbb 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -215,6 +215,25 @@ smartlist_string_num_isin(const smartlist_t *sl, int num)
   return smartlist_string_isin(sl, buf);
 }
 
+/** Return true iff the two lists contain the same strings in the same
+ * order, or if they are both NULL. */
+int
+smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2)
+{
+  if (sl1 == NULL)
+    return sl2 == NULL;
+  if (sl2 == NULL)
+    return 0;
+  if (smartlist_len(sl1) != smartlist_len(sl2))
+    return 0;
+  SMARTLIST_FOREACH(sl1, const char *, cp1, {
+      const char *cp2 = smartlist_get(sl2, cp1_sl_idx);
+      if (strcmp(cp1, cp2))
+        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/common/container.h b/src/common/container.h
index b39d4ca..f5e42de 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -42,6 +42,8 @@ int smartlist_string_pos(const smartlist_t *, const char *elt) ATTR_PURE;
 int smartlist_string_isin_case(const smartlist_t *sl, const char *element)
   ATTR_PURE;
 int smartlist_string_num_isin(const smartlist_t *sl, int num) ATTR_PURE;
+int smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2)
+  ATTR_PURE;
 int smartlist_digest_isin(const smartlist_t *sl, const char *element)
   ATTR_PURE;
 int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits