5 uint32_t isl_hash_string(uint32_t hash, const char *s)
8 isl_hash_byte(hash, *s);
12 static unsigned int round_up(unsigned int v)
23 int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
33 table->bits = ffs(round_up(4 * (min_size + 1) / 3 - 1)) - 1;
36 size = 2 << table->bits;
37 table->entries = isl_calloc_array(ctx, struct isl_hash_table_entry,
45 void isl_hash_table_clear(struct isl_hash_table *table)
52 struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx,
53 struct isl_hash_table *table,
55 int (*eq)(const void *entry, const void *val),
56 const void *val, int reserve)
61 key_bits = isl_hash_bits(key_hash, table->bits);
62 size = 2 << table->bits;
63 for (h = key_bits; table->entries[h].data; h = (h+1) % size)
64 if (table->entries[h].hash == key_hash &&
65 eq(table->entries[h].data, val))
66 return &table->entries[h];
71 assert(4 * table->n < 3 * size); /* XXX */
73 table->entries[h].hash = key_hash;
75 return &table->entries[h];
78 void isl_hash_table_remove(struct isl_ctx *ctx,
79 struct isl_hash_table *table,
80 struct isl_hash_table_entry *entry)
88 size = 2 << table->bits;
89 h = entry - table->entries;
90 isl_assert(ctx, h >= 0 && h < size, return);
92 for (h2 = h+1; table->entries[h2 % size].data; h2++) {
93 uint32_t bits = isl_hash_bits(table->entries[h2 % size].hash,
95 uint32_t offset = (size + bits - (h+1)) % size;
96 if (offset <= h2 - (h+1))
98 *entry = table->entries[h2 % size];
100 entry = &table->entries[h % size];