add isl_hash_table_every
authorSven Verdoolaege <sven@cerebras.net>
Fri, 4 Feb 2022 09:39:22 +0000 (4 10:39 +0100)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Sun, 1 Jan 2023 20:23:15 +0000 (1 21:23 +0100)
This will be used in the next commit.

Note that this function does not (currently) use the isl_ctx parameter.
It is added for consistency with the other isl_hash_table_* functions,
in particular isl_hash_table_foreach, which also does not use
its isl_ctx parameter.

Signed-off-by: Sven Verdoolaege <sven@cerebras.net>
include/isl/hash.h
isl_hash.c

index 7ef3d2e..31cf25c 100644 (file)
@@ -67,6 +67,8 @@ struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
                            const void *val, int reserve);
 isl_stat isl_hash_table_foreach(isl_ctx *ctx, struct isl_hash_table *table,
        isl_stat (*fn)(void **entry, void *user), void *user);
+isl_bool isl_hash_table_every(isl_ctx *ctx, struct isl_hash_table *table,
+       isl_bool (*test)(void **entry, void *user), void *user);
 void isl_hash_table_remove(struct isl_ctx *ctx,
                                struct isl_hash_table *table,
                                struct isl_hash_table_entry *entry);
index 1f57145..d0f6564 100644 (file)
@@ -230,6 +230,31 @@ isl_stat isl_hash_table_foreach(isl_ctx *ctx, struct isl_hash_table *table,
        return isl_stat_ok;
 }
 
+/* Does "test" succeed on every (non-empty) entry of "table"?
+ */
+isl_bool isl_hash_table_every(isl_ctx *ctx, struct isl_hash_table *table,
+       isl_bool (*test)(void **entry, void *user), void *user)
+{
+       size_t size;
+       uint32_t h;
+
+       if (!table->entries)
+               return isl_bool_error;
+
+       size = 1 << table->bits;
+       for (h = 0; h < size; ++ h) {
+               isl_bool r;
+
+               if (!table->entries[h].data)
+                       continue;
+               r = test(&table->entries[h].data, user);
+               if (r < 0 || !r)
+                       return r;
+       }
+
+       return isl_bool_true;
+}
+
 void isl_hash_table_remove(struct isl_ctx *ctx,
                                struct isl_hash_table *table,
                                struct isl_hash_table_entry *entry)