summaryrefslogtreecommitdiff
path: root/tests/test-hmap.c
diff options
context:
space:
mode:
authorAdrian Moreno <amorenoz@redhat.com>2022-03-23 12:56:17 +0100
committerIlya Maximets <i.maximets@ovn.org>2022-03-30 16:59:02 +0200
commit9e56549c2bba79e644de2d3876b363553175210c (patch)
treebf0bf39f86c3e63eda7171f727a6ca3dcc69922b /tests/test-hmap.c
parent860e69a8c3d6994dc000b37d682bd16cd2925bef (diff)
downloadopenvswitch-9e56549c2bba79e644de2d3876b363553175210c.tar.gz
hmap: use short version of safe loops if possible.
Using SHORT version of the *_SAFE loops makes the code cleaner and less error prone. So, use the SHORT version and remove the extra variable when possible for hmap and all its derived types. In order to be able to use both long and short versions without changing the name of the macro for all the clients, overload the existing name and select the appropriate version depending on the number of arguments. Acked-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'tests/test-hmap.c')
-rw-r--r--tests/test-hmap.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test-hmap.c b/tests/test-hmap.c
index 47b475538..e50c7c380 100644
--- a/tests/test-hmap.c
+++ b/tests/test-hmap.c
@@ -275,6 +275,38 @@ test_hmap_for_each_safe(hash_func *hash)
}
}
assert(n == n_remaining);
+ hmap_destroy(&hmap);
+
+ /* Test short version (without next variable). */
+ make_hmap(&hmap, elements, values, n, hash);
+
+ i = 0;
+ n_remaining = n;
+ HMAP_FOR_EACH_SAFE (e, node, &hmap) {
+ assert(i < n);
+ if (pattern & (1ul << e->value)) {
+ size_t j;
+ hmap_remove(&hmap, &e->node);
+ for (j = 0; ; j++) {
+ assert(j < n_remaining);
+ if (values[j] == e->value) {
+ values[j] = values[--n_remaining];
+ break;
+ }
+ }
+ }
+ check_hmap(&hmap, values, n_remaining, hash);
+ i++;
+ }
+ assert(i == n);
+ assert(e == NULL);
+
+ for (i = 0; i < n; i++) {
+ if (pattern & (1ul << i)) {
+ n_remaining++;
+ }
+ }
+ assert(n == n_remaining);
hmap_destroy(&hmap);
}