fix(hash table): fixed duplicate inserts for hash table

This commit is contained in:
Mineplay 2025-08-28 05:39:20 -05:00
parent 91e07ff6d0
commit ecbffdc112

View file

@ -119,12 +119,21 @@ FledastyError fledasty_hash_table_##name##_insert(FledastyHashTable_##name *curr
hallocy_free(previous_table); \
} \
\
const size_t index = current_hash_table->hash_function(key) % current_hash_table->capacity; \
\
FledastyHashTablePair_##name pair = { .key = key, .value = value }; \
fledasty_dynamic_array_fledasty_internal_pair_append(&current_hash_table->Table[index], pair); \
const size_t index = current_hash_table->hash_function(key) % current_hash_table->capacity; \
if (fledasty_dynamic_array_fledasty_internal_pair_has_value(&current_hash_table->Table[index], pair)) { \
size_t key_index = 0; \
while (!compare_key_function(current_hash_table->Table[index].buffer[key_index].key, key)) { \
key_index += 1; \
} \
\
current_hash_table->Table[index].buffer[key_index].value = value; \
return FLEDASTY_ERROR_VALUE_REPLACED; \
} \
\
fledasty_dynamic_array_fledasty_internal_pair_append(&current_hash_table->Table[index], pair); \
current_hash_table->size += 1; \
\
return FLEDASTY_ERROR_NONE; \
} \
\