util/set: Add a helper to resize a set
Often times you don't know how big a set will be and you want the code to just grow it as needed. However, sometimes you do know and you can avoid a lot of rehashing if you just specify a size up-front. Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
This commit is contained in:
@@ -280,6 +280,20 @@ set_rehash(struct set *ht, unsigned new_size_index)
|
||||
ralloc_free(old_ht.table);
|
||||
}
|
||||
|
||||
void
|
||||
_mesa_set_resize(struct set *set, uint32_t entries)
|
||||
{
|
||||
/* You can't shrink a set below its number of entries */
|
||||
if (set->entries > entries)
|
||||
entries = set->entries;
|
||||
|
||||
unsigned size_index = 0;
|
||||
while (hash_sizes[size_index].max_entries < entries)
|
||||
size_index++;
|
||||
|
||||
set_rehash(set, size_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the key with the given hash into the table.
|
||||
*
|
||||
|
||||
@@ -65,6 +65,8 @@ void
|
||||
_mesa_set_destroy(struct set *set,
|
||||
void (*delete_function)(struct set_entry *entry));
|
||||
void
|
||||
_mesa_set_resize(struct set *set, uint32_t entries);
|
||||
void
|
||||
_mesa_set_clear(struct set *set,
|
||||
void (*delete_function)(struct set_entry *entry));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user