add isl_hash_table_foreach
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 19 Feb 2010 12:08:52 +0000 (13:08 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 4 Mar 2010 13:24:35 +0000 (14:24 +0100)
include/isl_hash.h
isl_hash.c

index 60dc7c9..3c5ea3c 100644 (file)
@@ -61,6 +61,9 @@ struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
                                uint32_t key_hash,
                                int (*eq)(const void *entry, const void *val),
                                const void *val, int reserve);
+int isl_hash_table_foreach(struct isl_ctx *ctx,
+                               struct isl_hash_table *table,
+                               int (*fn)(void *entry));
 void isl_hash_table_remove(struct isl_ctx *ctx,
                                struct isl_hash_table *table,
                                struct isl_hash_table_entry *entry);
index 3a059a6..15df05a 100644 (file)
@@ -152,6 +152,21 @@ struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
        return &table->entries[h];
 }
 
+int isl_hash_table_foreach(struct isl_ctx *ctx,
+                               struct isl_hash_table *table,
+                               int (*fn)(void *entry))
+{
+       size_t size;
+       uint32_t h;
+
+       size = 1 << table->bits;
+       for (h = 0; h < size; ++ h)
+               if (table->entries[h].data && fn(table->entries[h].data) < 0)
+                       return -1;
+       
+       return 0;
+}
+
 void isl_hash_table_remove(struct isl_ctx *ctx,
                                struct isl_hash_table *table,
                                struct isl_hash_table_entry *entry)