summaryrefslogtreecommitdiffstats
path: root/src/util
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
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')
-rw-r--r--src/util/set.c14
-rw-r--r--src/util/set.h2
2 files changed, 16 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.
*
diff --git a/src/util/set.h b/src/util/set.h
index 7d277c59f8b..5742c311a77 100644
--- a/src/util/set.h
+++ b/src/util/set.h
@@ -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));