diff options
author | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2024-02-22 13:34:52 -0400 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-02-26 15:37:58 +0000 |
commit | d964f57a48994f3f737ac1885a6dc5b8a56c7edd (patch) | |
tree | d2684235992ca089a1b3ed2f20f70af62dc0f1f2 /src/util/hash_table.h | |
parent | cc1501628fd98bbf0f2a56d149347effb688722d (diff) |
util/hash_table: add u64 foreach macro
needs some nontrivial wrapping but can mostly fallback to the regular impl.
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27762>
Diffstat (limited to 'src/util/hash_table.h')
-rw-r--r-- | src/util/hash_table.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/util/hash_table.h b/src/util/hash_table.h index 002d6c58873..2091ad01580 100644 --- a/src/util/hash_table.h +++ b/src/util/hash_table.h @@ -171,6 +171,12 @@ struct hash_table_u64 { void *deleted_key_data; }; +struct hash_entry_u64 { + uint64_t key; + void *data; + struct hash_entry *_entry; +}; + struct hash_table_u64 * _mesa_hash_table_u64_create(void *mem_ctx); @@ -190,6 +196,22 @@ _mesa_hash_table_u64_remove(struct hash_table_u64 *ht, uint64_t key); void _mesa_hash_table_u64_clear(struct hash_table_u64 *ht); +struct hash_entry_u64 +_mesa_hash_table_u64_next_entry(struct hash_table_u64 *ht, + struct hash_entry_u64 *ent); + +/** + * This foreach function is safe against deletion (which just replaces + * an entry's data with the deleted marker), but not against insertion + * (which may rehash the table, making entry a dangling pointer). + */ +#define hash_table_u64_foreach(ht, entry) \ + for (struct hash_entry_u64 entry = \ + _mesa_hash_table_u64_next_entry(ht, NULL); \ + entry.data != NULL; \ + entry = _mesa_hash_table_u64_next_entry(ht, &entry)) + + #ifdef __cplusplus } /* extern C */ #endif |