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>
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.
*
_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));