diff options
author | Scott D Phillips <[email protected]> | 2018-05-02 09:01:02 -0700 |
---|---|---|
committer | Scott D Phillips <[email protected]> | 2018-05-04 10:13:33 -0700 |
commit | 5c075b085585b1629022d40ce7af9448c7d0e906 (patch) | |
tree | 62b7f9acb5843d1288ab17b475fabc49f5717d12 /src/util/set.c | |
parent | affe63b1da25dc7038499b6884523384684d70a8 (diff) |
util/set: add a set_clear function
Clear a set back to the state of having zero entries.
Reviewed-by: Kenneth Graunke <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/util/set.c')
-rw-r--r-- | src/util/set.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/set.c b/src/util/set.c index d71f771807f..2c9b09319ff 100644 --- a/src/util/set.c +++ b/src/util/set.c @@ -156,6 +156,29 @@ _mesa_set_destroy(struct set *ht, void (*delete_function)(struct set_entry *entr } /** + * Clears all values from the given set. + * + * If delete_function is passed, it gets called on each entry present before + * the set is cleared. + */ +void +_mesa_set_clear(struct set *set, void (*delete_function)(struct set_entry *entry)) +{ + struct set_entry *entry; + + if (!set) + return; + + set_foreach (set, entry) { + if (delete_function) + delete_function(entry); + entry->key = deleted_key; + } + + set->entries = set->deleted_entries = 0; +} + +/** * Finds a set entry with the given key and hash of that key. * * Returns NULL if no entry is found. |