string-map: New function string_map_equals().
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 2 Jan 2019 04:57:17 +0000 (20:57 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 2 Jan 2019 05:12:44 +0000 (21:12 -0800)
src/libpspp/string-map.c
src/libpspp/string-map.h

index ac32a35869d4e4055e1837c40b3a5d09a20564c9..edbd39e92488eb0fba985413ccfda9d1350da15c 100644 (file)
@@ -357,6 +357,25 @@ string_map_get_values (const struct string_map *map, struct string_set *values)
   STRING_MAP_FOR_EACH_VALUE (value, node, map)
     string_set_insert (values, value);
 }
+
+/* Returns true if A and B have the same content, false otherwise. */
+bool
+string_map_equals (const struct string_map *a, const struct string_map *b)
+{
+  if (string_map_count (a) != string_map_count (b))
+    return false;
+
+   const struct string_map_node *a_node;
+   STRING_MAP_FOR_EACH_NODE (a_node, a)
+     {
+       const struct string_map_node *b_node = string_map_find_node_with_hash (
+         b, a_node->key, strlen (a_node->key), a_node->hmap_node.hash);
+       if (!b_node || strcmp (a_node->value, b_node->value))
+         return false;
+     }
+
+   return true;
+}
 \f
 static struct string_map_node *
 string_map_find_node_with_hash (const struct string_map *map, const char *key,
index 3abc4ecc65cb2e7c5d374af4f2cc316918b4d9c3..7f2da1738c2d21ee59d1b332c5ae3e0526dea3c2 100644 (file)
@@ -116,6 +116,8 @@ void string_map_replace_map (struct string_map *, const struct string_map *);
 void string_map_get_keys (const struct string_map *, struct string_set *);
 void string_map_get_values (const struct string_map *, struct string_set *);
 
+bool string_map_equals (const struct string_map *, const struct string_map *);
+
 static inline struct string_map_node *string_map_first (
   const struct string_map *);
 static inline struct string_map_node *string_map_next (