Lines Matching refs:table
42 int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table,
47 if (!table)
52 table->bits = ffs(round_up(4 * (min_size + 1) / 3 - 1)) - 1;
53 table->n = 0;
55 size = 1 << table->bits;
56 table->entries = isl_calloc_array(ctx, struct isl_hash_table_entry,
58 if (!table->entries)
71 /* Extend "table" to twice its size.
74 * We reuse isl_hash_table_find to create entries in the extended table.
75 * Since all entries in the original table are assumed to be different,
78 static int grow_table(struct isl_ctx *ctx, struct isl_hash_table *table)
85 entries = table->entries;
86 old_size = 1 << table->bits;
88 table->entries = isl_calloc_array(ctx, struct isl_hash_table_entry,
90 if (!table->entries) {
91 table->entries = entries;
95 n = table->n;
96 table->n = 0;
97 table->bits++;
105 entry = isl_hash_table_find(ctx, table, entries[h].hash,
108 table->bits--;
109 free(table->entries);
110 table->entries = entries;
111 table->n = n;
125 struct isl_hash_table *table = NULL;
127 table = isl_alloc_type(ctx, struct isl_hash_table);
128 if (isl_hash_table_init(ctx, table, min_size))
130 return table;
132 isl_hash_table_free(ctx, table);
136 void isl_hash_table_clear(struct isl_hash_table *table)
138 if (!table)
140 free(table->entries);
143 void isl_hash_table_free(struct isl_ctx *ctx, struct isl_hash_table *table)
145 if (!table)
147 isl_hash_table_clear(table);
148 free(table);
158 struct isl_hash_table *table,
166 key_bits = isl_hash_bits(key_hash, table->bits);
167 size = 1 << table->bits;
168 for (h = key_bits; table->entries[h].data; h = (h+1) % size) {
171 if (table->entries[h].hash != key_hash)
173 equal = eq(table->entries[h].data, val);
177 return &table->entries[h];
183 if (4 * table->n >= 3 * size) {
184 if (grow_table(ctx, table) < 0)
186 return isl_hash_table_find(ctx, table, key_hash, eq, val, 1);
189 table->n++;
190 table->entries[h].hash = key_hash;
192 return &table->entries[h];
195 /* Return the first entry containing data in "table".
199 struct isl_hash_table_entry *isl_hash_table_first(struct isl_hash_table *table)
204 if (!table->entries)
207 size = 1 << table->bits;
209 if (table->entries[h].data)
210 return &table->entries[h];
215 isl_stat isl_hash_table_foreach(isl_ctx *ctx, struct isl_hash_table *table,
221 if (!table->entries)
224 size = 1 << table->bits;
226 if (table->entries[h].data &&
227 fn(&table->entries[h].data, user) < 0)
233 /* Does "test" succeed on every (non-empty) entry of "table"?
235 isl_bool isl_hash_table_every(isl_ctx *ctx, struct isl_hash_table *table,
241 if (!table->entries)
244 size = 1 << table->bits;
248 if (!table->entries[h].data)
250 r = test(&table->entries[h].data, user);
259 struct isl_hash_table *table,
265 if (!table || !entry)
268 size = 1 << table->bits;
269 h = entry - table->entries;
272 for (h2 = h+1; table->entries[h2 % size].data; h2++) {
273 uint32_t bits = isl_hash_bits(table->entries[h2 % size].hash,
274 table->bits);
278 *entry = table->entries[h2 % size];
280 entry = &table->entries[h % size];
285 table->n--;