Lines Matching refs:table
3 * Generic hash table.
46 * Create a new hash table.
48 * \return pointer to a new, empty hash table.
53 struct _mesa_HashTable *table = CALLOC_STRUCT(_mesa_HashTable);
55 if (table) {
56 table->ht = _mesa_hash_table_create(NULL, uint_key_hash,
58 if (table->ht == NULL) {
59 free(table);
64 _mesa_hash_table_set_deleted_key(table->ht, uint_key(DELETED_KEY_VALUE));
65 simple_mtx_init(&table->Mutex, mtx_plain);
71 return table;
77 * Delete a hash table.
78 * Frees each entry on the hash table and then the hash table structure itself.
79 * Note that the caller should have already traversed the table and deleted
80 * the objects in the table (i.e. We don't free the entries' data pointer).
82 * \param table the hash table to delete.
85 _mesa_DeleteHashTable(struct _mesa_HashTable *table)
87 assert(table);
89 if (_mesa_hash_table_next_entry(table->ht, NULL) != NULL) {
93 _mesa_hash_table_destroy(table->ht, NULL);
94 if (table->id_alloc) {
95 util_idalloc_fini(table->id_alloc);
96 free(table->id_alloc);
99 simple_mtx_destroy(&table->Mutex);
100 FREE(table);
103 static void init_name_reuse(struct _mesa_HashTable *table)
105 assert(_mesa_hash_table_num_entries(table->ht) == 0);
106 table->id_alloc = MALLOC_STRUCT(util_idalloc);
107 util_idalloc_init(table->id_alloc, 8);
108 ASSERTED GLuint reserve0 = util_idalloc_alloc(table->id_alloc);
113 _mesa_HashEnableNameReuse(struct _mesa_HashTable *table)
115 _mesa_HashLockMutex(table);
116 init_name_reuse(table);
117 _mesa_HashUnlockMutex(table);
121 * Lookup an entry in the hash table, without locking.
125 _mesa_HashLookup_unlocked(struct _mesa_HashTable *table, GLuint key)
129 assert(table);
133 return table->deleted_key_data;
135 entry = _mesa_hash_table_search_pre_hashed(table->ht,
146 * Lookup an entry in the hash table.
148 * \param table the hash table.
151 * \return pointer to user's data or NULL if key not in table
154 _mesa_HashLookup(struct _mesa_HashTable *table, GLuint key)
157 _mesa_HashLockMutex(table);
158 res = _mesa_HashLookup_unlocked(table, key);
159 _mesa_HashUnlockMutex(table);
165 * Lookup an entry in the hash table without locking the mutex.
167 * The hash table mutex must be locked manually by calling
170 * \param table the hash table.
173 * \return pointer to user's data or NULL if key not in table
176 _mesa_HashLookupLocked(struct _mesa_HashTable *table, GLuint key)
178 return _mesa_HashLookup_unlocked(table, key);
183 _mesa_HashInsert_unlocked(struct _mesa_HashTable *table, GLuint key, void *data)
188 assert(table);
191 if (key > table->MaxKey)
192 table->MaxKey = key;
195 table->deleted_key_data = data;
197 entry = _mesa_hash_table_search_pre_hashed(table->ht, hash, uint_key(key));
201 _mesa_hash_table_insert_pre_hashed(table->ht, hash, uint_key(key), data);
208 * Insert a key/pointer pair into the hash table without locking the mutex.
211 * The hash table mutex must be locked manually by calling
214 * \param table the hash table.
220 _mesa_HashInsertLocked(struct _mesa_HashTable *table, GLuint key, void *data,
223 _mesa_HashInsert_unlocked(table, key, data);
224 if (!isGenName && table->id_alloc)
225 util_idalloc_reserve(table->id_alloc, key);
230 * Insert a key/pointer pair into the hash table.
233 * \param table the hash table.
239 _mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data,
242 _mesa_HashLockMutex(table);
243 _mesa_HashInsert_unlocked(table, key, data);
244 if (!isGenName && table->id_alloc)
245 util_idalloc_reserve(table->id_alloc, key);
246 _mesa_HashUnlockMutex(table);
251 * Remove an entry from the hash table.
253 * \param table the hash table.
256 * While holding the hash table's lock, searches the entry with the matching
260 _mesa_HashRemove_unlocked(struct _mesa_HashTable *table, GLuint key)
264 assert(table);
271 assert(!table->InDeleteAll);
275 table->deleted_key_data = NULL;
277 entry = _mesa_hash_table_search_pre_hashed(table->ht,
280 _mesa_hash_table_remove(table->ht, entry);
283 if (table->id_alloc)
284 util_idalloc_free(table->id_alloc, key);
289 _mesa_HashRemoveLocked(struct _mesa_HashTable *table, GLuint key)
291 _mesa_HashRemove_unlocked(table, key);
295 _mesa_HashRemove(struct _mesa_HashTable *table, GLuint key)
297 _mesa_HashLockMutex(table);
298 _mesa_HashRemove_unlocked(table, key);
299 _mesa_HashUnlockMutex(table);
303 * Delete all entries in a hash table, but don't delete the table itself.
304 * Invoke the given callback function for each table entry.
306 * \param table the hash table to delete
312 _mesa_HashDeleteAll(struct _mesa_HashTable *table,
317 _mesa_HashLockMutex(table);
319 table->InDeleteAll = GL_TRUE;
321 hash_table_foreach(table->ht, entry) {
323 _mesa_hash_table_remove(table->ht, entry);
325 if (table->deleted_key_data) {
326 callback(table->deleted_key_data, userData);
327 table->deleted_key_data = NULL;
329 if (table->id_alloc) {
330 util_idalloc_fini(table->id_alloc);
331 free(table->id_alloc);
332 init_name_reuse(table);
335 table->InDeleteAll = GL_FALSE;
337 table->MaxKey = 0;
338 _mesa_HashUnlockMutex(table);
343 * Walk over all entries in a hash table, calling callback function for each.
344 * \param table the hash table to walk
350 hash_walk_unlocked(const struct _mesa_HashTable *table,
354 assert(table);
357 hash_table_foreach(table->ht, entry) {
360 if (table->deleted_key_data)
361 callback(table->deleted_key_data, userData);
366 _mesa_HashWalk(const struct _mesa_HashTable *table,
371 struct _mesa_HashTable *table2 = (struct _mesa_HashTable *) table;
374 hash_walk_unlocked(table, callback, userData);
379 _mesa_HashWalkLocked(const struct _mesa_HashTable *table,
383 hash_walk_unlocked(table, callback, userData);
387 * Dump contents of hash table for debugging.
389 * \param table the hash table.
392 _mesa_HashPrint(const struct _mesa_HashTable *table)
394 if (table->deleted_key_data)
395 _mesa_debug(NULL, "%u %p\n", DELETED_KEY_VALUE, table->deleted_key_data);
397 hash_table_foreach(table->ht, entry) {
407 * \param table the hash table.
412 * If there are enough free keys between the maximum key existing in the table
418 _mesa_HashFindFreeKeyBlock(struct _mesa_HashTable *table, GLuint numKeys)
421 if (table->id_alloc && numKeys == 1) {
422 return util_idalloc_alloc(table->id_alloc);
423 } else if (maxKey - numKeys > table->MaxKey) {
425 return table->MaxKey + 1;
433 if (_mesa_HashLookup_unlocked(table, key)) {
453 _mesa_HashFindFreeKeys(struct _mesa_HashTable *table, GLuint* keys, GLuint numKeys)
455 if (!table->id_alloc) {
456 GLuint first = _mesa_HashFindFreeKeyBlock(table, numKeys);
464 keys[i] = util_idalloc_alloc(table->id_alloc);
472 * Return the number of entries in the hash table.
475 _mesa_HashNumEntries(const struct _mesa_HashTable *table)
479 if (table->deleted_key_data)
482 count += _mesa_hash_table_num_entries(table->ht);