From c887a18a101de5140494a42be54a0907dd3b3718 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sat, 20 Jun 2026 15:26:31 +0100 Subject: [PATCH] fx.collections: hashtable: fix index calculation issues --- fx.collections/hashtable.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fx.collections/hashtable.c b/fx.collections/hashtable.c index c2de440..5f58dd5 100644 --- a/fx.collections/hashtable.c +++ b/fx.collections/hashtable.c @@ -68,9 +68,14 @@ static fx_status convert_key_to_index( return status; } - size_t index = hash % table_size, i = 1; + size_t base_index = hash % table_size; + size_t index = base_index, i = 0; bool index_found = false; - while (table[index].i_item && i <= table_size) { + while (i <= table_size) { + if (!table[index].i_item) { + goto skip; + } + const struct fx_hashtable_item_p *item = fx_object_get_private( table[index].i_item, FX_TYPE_HASHTABLE_ITEM); @@ -80,7 +85,8 @@ static fx_status convert_key_to_index( break; } - index = (index + (i * i)) % table_size; + skip: + index = (base_index + (i * i)) % table_size; i++; } @@ -108,7 +114,7 @@ static fx_status allocate_index_for_key( size_t index = hash % table_size; bool ok = false; - for (size_t i = 1; i < table_size; i++) { + for (size_t i = 0; i < table_size; i++) { if (!table[index].i_item) { ok = true; break;