struct isl_ctx;
int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
- int init_bits);
+ int min_size);
void isl_hash_table_clear(struct isl_hash_table *table);
struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
struct isl_hash_table *table,
return hash;
}
+static unsigned int round_up(unsigned int v)
+{
+ int old_v = v;
+
+ while (v) {
+ old_v = v;
+ v ^= v & -v;
+ }
+ return old_v << 1;
+}
+
int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
- int init_bits)
+ int min_size)
{
size_t size;
if (!table)
return -1;
- if (init_bits < 2)
- init_bits = 2;
- table->bits = init_bits;
+ if (min_size < 2)
+ min_size = 2;
+ table->bits = ffs(round_up(4 * (min_size + 1) / 3 - 1)) - 1;
table->n = 0;
size = 2 << table->bits;