From 1516eee8d111d42c85720c1a7a87f9cb186ae9b2 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 29 May 2026 20:02:48 +0100 Subject: [PATCH] fx.collections: hashtable: update allocate_index_for_key to handle exact key matches --- fx.collections/hashtable.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fx.collections/hashtable.c b/fx.collections/hashtable.c index 8ce5798..54c556e 100644 --- a/fx.collections/hashtable.c +++ b/fx.collections/hashtable.c @@ -114,6 +114,15 @@ static fx_status allocate_index_for_key( break; } + const struct fx_hashtable_item_p *item = fx_object_get_private( + table[index].i_item, + FX_TYPE_HASHTABLE_ITEM); + int cmp = fx_value_compare(&item->i_key, v); + if (cmp == 0) { + ok = true; + break; + } + index = (index + (i * i)) % table_size; i++; } @@ -277,7 +286,6 @@ static fx_status hashtable_put( fx_value_copy(&item_p->i_key, key); fx_value_copy(&item_p->i_value, value); - assert(hashtable->t_items[index].i_item == NULL); hashtable->t_items[index].i_item = item; hashtable->t_count++; return FX_SUCCESS;