5 uint32_t isl_hash_string(uint32_t hash, const char *s)
8 isl_hash_byte(hash, *s);
12 int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
22 table->bits = init_bits;
25 size = 2 << table->bits;
26 table->entries = isl_calloc_array(ctx, struct isl_hash_table_entry,
34 void isl_hash_table_clear(struct isl_hash_table *table)
41 struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
42 struct isl_hash_table *table,
44 int (*eq)(const void *entry, const void *val),
45 const void *val, int reserve)
50 key_bits = isl_hash_bits(key_hash, table->bits);
51 size = 2 << table->bits;
52 for (h = key_bits; table->entries[h].data; h = (h+1) % size)
53 if (table->entries[h].hash == key_hash &&
54 eq(table->entries[h].data, val))
55 return &table->entries[h];
60 assert(4 * table->n < 3 * size); /* XXX */
62 table->entries[h].hash = key_hash;
64 return &table->entries[h];
67 void isl_hash_table_remove(struct isl_ctx *ctx,
68 struct isl_hash_table *table,
69 struct isl_hash_table_entry *entry)
77 size = 2 << table->bits;
78 h = entry - table->entries;
79 isl_assert(ctx, h >= 0 && h < size, return);
81 for (h2 = h+1; table->entries[h2 % size].data; h2++) {
82 uint32_t bits = isl_hash_bits(table->entries[h2 % size].hash,
84 uint32_t offset = (size + bits - (h+1)) % size;
85 if (offset <= h2 - (h+1))
87 *entry = table->entries[h2 % size];
89 entry = &table->entries[h % size];