isl_hash.c: reset the number of entries to 0 when growing the hash table
authorMythri Alle <mythri.allel@gmail.com>
Sun, 8 Jul 2012 14:27:01 +0000 (16:27 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 8 Jul 2012 16:22:50 +0000 (18:22 +0200)
The hash table is grown by creating a new table and adding the entries
of the old table to the new table.  Since the new table starts out as
being empty, the number of entries should be reset to 0.

Not only would the old code result in isl_union_map_n_map returing
the wrong value if the underlying hash table had ever been grown,
it would also result in the table subsequently being grown again
far too early.

Signed-off-by: Mythri Alle <mythri.alle@gmail.com>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_hash.c

index c997402..0ce66bf 100644 (file)
@@ -64,6 +64,7 @@ int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
 static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table,
                        int (*eq)(const void *entry, const void *val))
 {
+       int n;
        size_t old_size, size;
        struct isl_hash_table_entry *entries;
        uint32_t h;
@@ -78,6 +79,8 @@ static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table,
                return -1;
        }
 
+       n = table->n;
+       table->n = 0;
        table->bits++;
 
        for (h = 0; h < old_size; ++h) {
@@ -92,6 +95,7 @@ static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table,
                        table->bits--;
                        free(table->entries);
                        table->entries = entries;
+                       table->n = n;
                        return -1;
                }