aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/set.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2019-05-10 13:50:56 -0500
committerJason Ekstrand <[email protected]>2019-05-13 14:43:47 +0000
commitbab08c791de323f021bcedbd93aee04343637482 (patch)
tree4a1e17f9cded00757c177d13f99c66cf8344894d /src/util/set.c
parentabb450870e8a8fc590e53b21f3ff2a4db42536dd (diff)
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 <[email protected]> Reviewed-by: Thomas Helland <[email protected]>
Diffstat (limited to 'src/util/set.c')
-rw-r--r--src/util/set.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/set.c b/src/util/set.c
index 2fd54a71a6f..c2b97bdea08 100644
--- a/src/util/set.c
+++ b/src/util/set.c
@@ -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.
*