aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-12-22 16:07:43 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-12-22 16:07:43 -0500
commit6f1ed65de90c387c3e38867b592c8fa7c8cfa80a (patch)
tree9084159824a031e133a027dbd67978f89695b83d
parent3dd7854076c5f49032ad520dc56769faa1c35d08 (diff)
Tweak table resizing policy
-rw-r--r--stdlib/tables.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/stdlib/tables.c b/stdlib/tables.c
index 38e98ccc..ac8bebc8 100644
--- a/stdlib/tables.c
+++ b/stdlib/tables.c
@@ -231,7 +231,7 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const
int64_t key_size = type->TableInfo.key->size,
value_size = type->TableInfo.value->size;
if (!t->bucket_info || t->bucket_info->count == 0) {
- hashmap_resize_buckets(t, 4, type);
+ hashmap_resize_buckets(t, 8, type);
} else {
// Check if we are clobbering a value:
void *value_home = Table$get_raw(*t, key, type);
@@ -251,7 +251,8 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const
// Resize buckets if necessary
if (t->entries.length >= (int64_t)t->bucket_info->count) {
- uint32_t newsize = (uint32_t)t->bucket_info->count + MIN((uint32_t)t->bucket_info->count, 64);
+ // Current resize policy: +50% at a time:
+ uint32_t newsize = (3*(uint32_t)t->bucket_info->count)/2;
if (unlikely(newsize > TABLE_MAX_BUCKETS))
newsize = t->entries.length + 1;
hashmap_resize_buckets(t, newsize, type);